5.类型转换的问题


//操作比较大的数的时候
//JDK7新特性,数字之间可以用下划线分割
int money = 10_0000_0000;
int years = 20;
int total1 = money * years;//-1474836480 计算的时候溢出了
long total2 = money * years;//由于默认是int类型 这是转换之前就存在的问题

long total3 = ((long)money) * years;
System.out.println(total3);


posted @ 2021-11-18 13:01  在风雨中的她  阅读(22)  评论(0)    收藏  举报