数据转换的注意事项

public class demo6 {
public static void main(String[] args) {
//操作比较大的数字的时候,注意溢出问题;
//JDK7新特性 ,数字之间可以用下划线分割
int money = 10_0000_0000;
System.out.println(money);
int years = 20 ;
// int total = money*years; 计算的时候溢出了
// long total = money*years; 默认是int
long total = money*((long)years); //先把一个数转换为long,在进行计算

System.out.println(total);



}
posted @ 2021-10-29 14:05  猪肉炖粉条香香香  阅读(36)  评论(0)    收藏  举报