public class TestClass7 { public static void main(String[] args) throws Exception { System.out.println(Integer.MIN_VALUE); int a = Integer.MIN_VALUE; int b = -a; System.out.println( a+ " "+b); } }
The output is -2147483648 -2147483648.Please explain why the output is not -2147483648 2147483648.
Java stores integers in two's complement format. The range for a 32-bit integer is -2^31 (-2147483648) to 2^31 - 1 (2147483647). The number 2147483648 (which is 2^31) does not fit in an integer.