PDA

View Full Version : What is the logic of the output of this program?


PeytonPhelps
Nov 7, 2016, 07:11 PM
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.