I have the following method:
int x= (int) Math.pow(2, 5);
for (int k=1; k <= 3; k++) {
x *= (2*x);
}
System.out.println(x); // prints 0
It is simply initializing x to 32 and then multiplying it by its double every iteration of the loop. However, I expect the output the be a big number or at least an error, but the final output is 0. No, I tried to do some debugging by adding this:
int x= (int) Math.pow(2, 5);
for (int k=1; k <= 3; k++) {
System.out.println(x + " * " + 2 * x);
x *= (2*x);
}
System.out.println(x);
But the output is this:
32 * 64
2048 * 4096
8388608 * 16777216
0
Does anyone have any idea why the number suddenly becomes 0?