+ 1
Why the output is 2 ?
Why the output is 2?? public class test { public static void main(String [] args) { int x=0; for(int z =0 ;z<5;z++) { if((z>2) && (++x>2)) { x+=7; }} System.out.print(x); } }
2 Answers
+ 3
for z=3
z>2 but ++x=1 is not greater than 2
for z=4
z>2 but ++x=2 is not greater than 2
for z=5
loop terminates..
and finally x=2
and gets printed..
+ 3
@thanks Sami