public class Demo05 {
public static void main(String[] args) {
//操作比较大的数的时候注意溢出问题
//jdk7的新特性,数字之间可以用下划线分割
int money = 10_1234_1234;
System.out.println(money); //1012341234
int years = 20;
int total = money*years;
System.out.println(total); //输出负数,因为计算的时候溢出了
long total2 = money*years;
System.out.println(total2); //默认是int,转换之前已经存在问题了
long total3 = money*((long)years);
System.out.println(total3); //20246824680
}
}
运行结果