源程序:
public class Test{
public static void main(String args[]){
int max = Integer.MAX_VALUE;
System.out.println("整型的最大值:"+max);
System.out.println("整型的最大值 + 1:"+(max+1));
System.out.println("整型的最大值 + 2:"+(max+2l));
System.out.println("整型的最大值 + 2:"+((long)max+2));
}
}
![使用强制类型转换,防止数据溢出 使用强制类型转换,防止数据溢出](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
运行结果:
![使用强制类型转换,防止数据溢出 使用强制类型转换,防止数据溢出](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)