+ 2
Java code
How this code runs https://code.sololearn.com/czpzCi58SNdC/?ref=app
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
+ 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);
}
+ 1
Airree Thanks, im so careless...
+ 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.