0

Noob question about 'for' and x=x*x

In the case with the code below: public class Program { public static void main(String[] args) { for(int x=2; x<=10; x=x*x) { System.out.println(x); } } } May I ask why did it output 2 and 4 instead of 4? Or perhaps did I misunderstood x=x*x as 2*2 (equal 4), then the new x value (4) become 4*4 (equal to 16) which is invalid? Please let me know.

30th Jul 2019, 7:34 PM
Rei
Rei - avatar
3 Answers
+ 1
~ swim ~ Thank you very much!
30th Jul 2019, 7:41 PM
Rei
Rei - avatar