提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
检查int溢出的结果
public class Main { public static void main(String[] args) { /* 时 代 Java - nowjava.com */ int n = 2147483647; //2^31-1; int nval = n + 1; System.out.println("If n=" + n + " then n+1=" + nval); long m = 9223372036854775807L; long mval = m + 1; System.out.println("If m=" + m + " then m+1=" + mval); } }