public class Demo3 {
//类型转换的溢出问题
public static void main(String[] args) {
//操作比较大的数时,注意溢出问题
//JDK7新特性,数字之间可以用下划线分割
int money = 10_0000_0000;
int year = 20;
int total = money*year;//-1474836480,计算的时候溢出了
long total2 = money *((long)years);//先把一个数转换为Long
System.out.println(total2);
//
}
}
原文:https://www.cnblogs.com/yzlDeity/p/14684667.html