15th Jun 2019, 3:05 PM
Tzion
Tzion - avatar
5 Respostas
+ 3
It has an integer x, that is incremented in the for loop every iteration and also gets squared. Lets break it down to pieces: First, it is squared x = 1 * 1 = 1 then incremented x = 1 + 1 = 2 then squared x = 2 * 2 = 4 then incremented again x = 4 + 1 = 5 then squared for the last time x = 5 * 5 = 25 then incremented at the end x = 25 + 1 = 26
15th Jun 2019, 3:11 PM
Airree
Airree - avatar
+ 4
I agree with the guys above. Just one more tiny thing, in codes like this it would be beneficial to print each pass through the loop, so you can understand better what's happening in each iteration. Just put the brackets, it's almost self-explanatory : for(;x < 6;x++){ x *= x; System.out.println(x); }
15th Jun 2019, 3:25 PM
dρlυѕρlυѕ
dρlυѕρlυѕ - avatar
+ 1
Airree Thanks, im so careless...
15th Jun 2019, 4:04 PM
Tzion
Tzion - avatar
+ 1
~ swim ~ My brain keep ignore the x++, too carelessness about it,i've asked so much questions same like this little careless mistake,especially x++,i dont know why my brain keep ignore it repeatly.
15th Jun 2019, 4:07 PM
Tzion
Tzion - avatar