当int类型不断增加超出范围会发生什么


public class IntOuOfBounds {
public static void main(String[] args) {
int i = 2;
while (true) {
i *= Math.pow(2, i);
System.out.println(i);
}
}
}

输出结果如下

2147483647
2147483647
2147483647
2147483647
2147483647
2147483647
2147483647
2147483647
2147483647
2147483647
2147483647

....

到达上限值不再变化。2^32-1

猜你喜欢

转载自www.cnblogs.com/bowenqianngzhibushiwo/p/11651110.html