让int型数据溢出
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
int i = 0;
// int的最大值2^31-1
i = (int) (Math.pow(2, 31) - 1);
if (i + 1 < i) {
System.out.println("溢出");
} else {
System.out.println("未溢出");
}
}
}
结果输出:
溢出