0

Explain This Please??

int x=1; int y=3; for(int i=3; i<5; i++){ x+=i; System.out.println(x); } } Output is: 4 8 Then if i change print int x=1; int y=3; for(int i=3; i<5; i++){ System.out.println(x) x+=i; ; } } Output is: 1 4

14th Jul 2019, 1:10 PM
masum billah sanjid
masum billah sanjid - avatar
2 Answers
+ 3
x=1 x=x+i - - > 1+3 - - >4 i++ - - > 4 x+x+i - - > 4+4 - - > 8 x=1 print 1 then x=x+i--> 1+3-->4 i++ - - > 4 print 4 then x=x+i - - > x=4+4 - - >8 and 8 is not < 5 so the loop breaks
14th Jul 2019, 1:15 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
Thanks
14th Jul 2019, 1:22 PM
masum billah sanjid
masum billah sanjid - avatar