What’s the Output?
The product of two 32-bit integers is a 64-bit number. If the 32 most significant bits are zero, then the result is simply the 32 least significant bits. However, if the most significant 32 bits are not zero, then overflow has occurred, but Java does not throw an ArithmeticException. Instead, Java returns the 32 least significant bits of the product. Indeed, the evaluation of the multiplication operator * on integers neverthrows a runtime exception.
a. What is the output of the following program?
public class Testint { public static void main(String[ ] args) { Integer x = 2; for (int i = 0; i<10; i++) { x = x * x; System.out.println(x.equals(0)); } } }b. What happens if
int x = 2; replaces Integer x = 2;?
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.