+ 1

Please explain

for (int x = 6; x < x * x; - - x) { System.out.print(x); } output: 2 (last num. that will be printed)

25th Mar 2022, 8:47 AM
Eyy
3 Answers
+ 4
Output is 65432. 6 < 6*6 is true 5 < 5*5 ... 1 < 1*1 is false hence, loop stops.
25th Mar 2022, 8:56 AM
Simba
Simba - avatar
+ 2
Simba is right. if you want to get it to negative integers use "<=" operator instead of "<" operator. But that way, it will be an infinite loop.
25th Mar 2022, 8:58 AM
Adil
Adil - avatar
+ 1
thanks!!!
25th Mar 2022, 9:04 AM
Eyy