数据类型与强制类型转换

八大基本数据类型

int  short byte long --float double --char--Boolean

long与float 后面需要加F,L;

public class type {
    public static void main(String[] args) {
        int a =128;
        short b=2;
        long c = 3L;
        char d = 'a';
        float e = 3.13513F;
        double f = 3.65;
        String g = "你好帅";
        byte h = (byte)a;//内存溢出
        /*强制转换 (类型)变量名 高--低
        自动转换 低--高
        不能对boolean类型转换
        不能转换成不相干的类型
        高容量转成低容量需要强制转换
        转换时可能出现内存溢出,或者精度问题*/
        System.out.println(h);
        //操作比较大的数时候,注意溢出问题
        //jdk7新特性,数字之间可以用下划线分割
        int money = 10_0000_0000;
        int years = 20;
        int total = money*years;
        long total2 = money*(long)years;
        System.out.println(total);
        System.out.println(total2);
        //L尽量用大写F L    

    }
}

 

posted @ 2023-10-25 03:13  Xue_yong  阅读(22)  评论(0)    收藏  举报