数据类型拓展

数据类型拓展

        //整数拓展-进制  二进制0b..  八进制0.. 十六进制0x..
        int a1 = 10;
        int a2 = 0b10;
        int a3 = 010;
        int a4 = 0x10;

        System.out.println(a1);  //10
        System.out.println(a2);  //2
        System.out.println(a3);  //8
        System.out.println(a4);  //16
        System.out.println("-----------------");

        // 浮点数拓展  银行业务怎么表示? float?double?  --答案:BigDecimal 数据工具类
        // float 范围有限 离散 舍入误差 大约 接近但不等于  --!避免使用浮点数
        // double
        float f = 0.1f; //0.1
        double d = 1.0/10; //0.1

        System.out.println(f==d); //false
        System.out.println(f); //0.1
        System.out.println(d); //0.1

        System.out.println("-----------------");
        float f1 = 21212121212f;
        float f2 = f1+1;
        System.out.println(f1==f2);//true

        System.out.println("-----------------");
        // 字符拓展  !所有字符本质是数字
        // 编码 Unicode 2字节 0-65536
        char c1 = 'a';
        char c2 = '中';
        System.out.println(c1);
        System.out.println(c2);
        System.out.println((int)c1); //强制转换
        System.out.println((int)c2);
        System.out.println("-----------------");

        //转义字符
        // \t  tab
        // \n  换行
        System.out.println("H\tello\nworld");
        System.out.println("-----------------");

        //String 拓展
        String s1 = new String("hehe");
        String s2 = new String("hehe");
        String s3 = "hehe";
        String s4 = "hehe";
        System.out.println(s1==s2); //new 对象比较 即使内容相对对象不是同一个,内存地址不同
        System.out.println(s3==s4); //指向同一地址“hehe”
        System.out.println("-----------------");
posted @ 2022-12-31 12:50  LaViez  阅读(22)  评论(0)    收藏  举报