数据类型扩展

public class Demo03 {
    public static void main(String[] args) {
        //整数拓展: 二进制0b 十进制 八进制0 十六进制0x
        int i = 10;
        int i2 = 010;//八进制
        int i3 = 0x10;//十六进制 0-9 A-F 16
        System.out.println(i);//10
        System.out.println(i2);//8
        System.out.println(i3);//16

        //浮点数拓展=======================================
        //银行业务怎么表示?钱
        //Bigdecimal 数学工具类
        //float:有限 离散 舍入误差 大越接近但不等于
        //double:
        //最好完全避免使用浮点数进行比较
        float f = 0.1f;
        double b = 0.1;
        System.out.println(f == b);//false
        float d1 = 2323232323323232332f;
        float d2 = d1 + 1;
        System.out.println(d1 == d2);

        //字符拓展=========================================
        char c1 = 'a';
        char c2 = '中';
        char c3 = 97;
        System.out.println(c1);
        System.out.println((int) c1);//强制转换

        System.out.println(c2);
        System.out.println((int) c2);//强制转换

        System.out.println(c3);//输出为a
        //所有的字符本质还是数字
        //编码 Unicode 2字节 0-65536 U0000-UFFFF
        //表 97=a  65=A;
        char c4 = '\u0061';
        System.out.println(c4);//a

        //转义字符
        //  \t 制表符(空格);
        //  \n 换行;
        System.out.println("hello\tworld");
        System.out.println("hello\nworld");
        System.out.println("\"");// \不能输出

        //=====================================================
        String sa = new String("hello");
        String sb = new String("hello");
        System.out.println(sa == sb);

        String sc = "hello";
        String sd = "hello";
        System.out.println(sc == sd);
        //对象 从内存分析

        //布尔值拓展
        boolean flag = true;
        if (flag ==true) { }//新手
        if (flag) { }//老手
    }
}
posted @ 2021-03-05 14:35  做一个好人  阅读(41)  评论(0)    收藏  举报