09类型转换

类型转换

public class Demo25 {
    public static void main(String[] args) {
        int i= 128;
        byte b=(byte)i;
        System.out.println(b);
        System.out.println("=================");
        //高到低强制转换
        //低到高可以直接写
        /*
        不能对布尔转换
        不能把对象类型转换
        转换时可能会内存溢出
        精度可能存在问题
        */
        char c='a';
        int d=c+1;
        System.out.println(d);
        System.out.println((char)d);
        System.out.println("===============");
        int money=10_0000_0000;
        int years=20;
        int total=money*years;
        long total2=money*years;
        long total3=(long)money*years;
        System.out.println(total);
        System.out.println(total2);
        System.out.println(total3);
    }
}
  • 笔记
posted on 2021-02-06 23:10  小黑鱼与妖精  阅读(53)  评论(0)    收藏  举报