- 1

Java challenge

Hello there! Someone could tell me how 52 the output of this code? int x = 0; int y = 0; for (int z = 1; z < 5; z++) { if (( ++x > 2) && (++y > 1)) { x++; } } System.out.println(x +""+ y); I see how x increasing with x++, but I can't understand how y works. I am kind of new at Sololearn. Any chance that are the challenges have wrong solution?

18th May 2021, 10:39 PM
CEORF
CEORF - avatar
1 Answer
+ 1
52 is correct U just need to learn about the concept of short circuiting in logical operators. The condn ++y will not be evaluated until ++x >2 is true.
19th May 2021, 4:18 PM
[ ]
[     ] - avatar