The code fragment
int x = < an integer value >; System.out.println(x*x);
displays
-131071
. Which of the following is a possible value ofx
?
Apparently the answer is 2^16 - 1
.
I don't even know how that was an answer choice. How am I supposed to solve this problem without a calculator?
The statement
System.out.println(Integer.MAX_VALUE);
prints
2147483647
, which is equal to2^31 - 1
. What does the following statement print?System.out.println(Integer.MAX_VALUE + 2);
The answer was -2137483546
. I'm confused how, shouldn't it cause an ArithmeticException since we're going out of bounds?
I'm not asking these questions for you to do them for me? If you could give me the reasoning and not just the answers (which I already have)? I'm just confused about manipulating with ints
near their max values.