public static void main(String[] args) { int i = 200 * 300 * 400 * 500; System.out.println(i); long j = (200L * 300L * 400L * 500L); System.out.println(j); }
输出
-884901888
12000000000
原因:计算机的表示法是用有限数量的位对一个数字进行编码,因此,当结果太大以至于不能表示时,某些运算就会溢出。
时刻记着int的取值范围为 -2147483648~2147483647,别溢出了!