类型转换(2)

 1 public class demo3 {
 2     public static void main(String[] args) {
 3         //操作比较大的数的时候,注意溢出问题
 4         //JDK7新特性,数字之间可以用下划线分割
 5         int money = 10_0000_0000;
 6         int years = 20;
 7         int total = money+years;//-1474836480,计算的时候溢出了
 8         long total2 = money *years;//默认是int,转换之前已经存在问题了?
 9 
10         long total3 = money*((long)years);//先把一个数转换为Long
11         System.out.println(total3);
12 
13         //L    L
14     }
15 }

 

posted @ 2021-03-11 22:55  HeartlessHero  阅读(34)  评论(0)    收藏  举报