+ 3

How come this program produces a output of 52?

INT x=0; y=0; for(INT z=1,z<5;z++) { if((++x>2) && (++y>1)) { x++; } } System.out.println(x+""+y);

8th Jun 2017, 4:18 AM
Shravan Kumar
Shravan Kumar - avatar
2 ответов
+ 4
It would produce error. There's many syntax errors here. Disregarding that, z = 1. Is ++x > 2? no, x = 1, z = 2 Is ++x > 2 no, x = 2, z = 3 Is ++x > 2 Yes, x = 3 Now we can check y Is ++y > 1 no, y = 1, z = 4 Is ++ x > 2 Yes, x = 4 Is ++y > 1 Yes, y = 2 x++, z = 5 x = 5 5 < 5 is false, so loop stops. (Using z here) Output: 52
8th Jun 2017, 4:46 AM
Rrestoring faith
Rrestoring faith - avatar
8th Jun 2017, 4:59 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar