output - pre-increment and post-increment
public static void main(String [] args)
{
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++)
{
if (( x++ > 2 ) || (y++ > 2))
{
x++;
}
}
System.out.println(x + " " + y);
}
Output is: 7 3
public static void main(String [] args)
{
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++)
{
if (( ++x > 2 ) || (++y > 2))
{
x++;
}
}
System.out.println(x + " " + y);
}
Output is: 8 2
Two things you should notice:
- defference between pre-increment and post-increment
- boolean expression: a. for logic add, if the former condition is false, the following conditions won’t be evaluated b. for logic or, if the former condition is true, the following conditions won’t be evaluated