Ask Experts Questions for FREE Help !
Ask
    PeytonPhelps's Avatar
    PeytonPhelps Posts: 1, Reputation: 1
    New Member
     
    #1

    Nov 7, 2016, 07:11 PM
    What is the logic of the output of this program?
    public class Main
    {
    public static void main(String[]args)
    {
    int y = 12;
    int z = 0;

    for (int index = 0; index <= y; index++)
    {
    if ((index % 3 == 0) && (index % 2 == 0))
    {
    z--;
    }
    else
    {
    z++;
    }
    }
    System.out.println(z);
    }

    Does Java go through the (index % 3 == 0) & (index % 2 == 0)
    or just the first one - (index % 3 == 0)?


    I don't know.. lol.

Check out some similar questions!

Java program, logic error [ 1 Answers ]

So I have to write a program to calculate the amount of sale an employee need to make in order for her to earn 30 000$. Her income comes from 2 sources. One of them is her base salary which is 5000$, and the other is her commission. Here is how the commission work. If her sale is from 0 - 5000, she...

Why output is not 121212 in following java code but the output is |||? [ 1 Answers ]

please help in following java code, I have to write 121212 ten times in poll.txt file but when I open poll.txt file it shows me |||||||||| output import java.io.*; class Byte{ public static void main(String args) throws IOException { try{FileOutputStream f=new FileOutputStream("poll.txt");...

Program that convert a NFA to an equivalent DFA,I found this program in C [ 0 Answers ]

Program that convert a NFA to an equivalent DFA,by C++

To get higher wattage output in a lower output fixture. [ 1 Answers ]

We purchased a Harbor Breeze fan with light fixture, but did not see that the wattage output was only going to be 40 watts. We need more lighting in our room. We have tried bigger watt bulbs but the fixture starts to blink and then goes dim(back to the 40 watt output). How can we change that?


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.