数据类型拓展及面试题

public class Demo01 {
    public static void main(String[] args) {
        //整数拓展   进制    二进制0b   十进制  八进制0   十六进制0x
        int a1 = 10;
        int a2 = 0b10;
        int a3 = 010;
        int a4 = 0x10;
        System.out.println(a1);
        System.out.println(a2);
        System.out.println(a3);
        System.out.println(a4);
        System.out.println("-----------------------------------------");

        //浮点数拓展  银行业务怎么表示?钱
        //  BigDecimal  数学工具类
        //float 有限  离散  舍入误差  大约  接近但不等于
        //double
        //最好完全避免使用浮点数进行比较
        //最好完全避免使用浮点数进行比较
        //最好完全避免使用浮点数进行比较
        float i = 0.1f;
        double i1 = 0.1;
        System.out.println(i == i1);  //false
        System.out.println(i);
        System.out.println(i1);
        float i2 = 123165345623416451264f;
        float i3 = i2 + 1;
        System.out.println(i2 == i3);//true
        //字符拓展
        char b1 = 'a';
        char b2 = '中';
        System.out.println(b1);
        System.out.println((int) b1);//强制转换
        System.out.println(b2);
        System.out.println((int) b2);//强制转换
        //所有字符本质还是数字
        //编码 Unicode 表:(97=a 65=A) 2字节 0-65536    Excel   2的16次方
        //U0000 UFFFF
        char b3 = '\u0061';
        System.out.println(b3);//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");
        String sc = "Hello";
        String sd = "Hello";
        System.out.println(sa == sb);//比较的是内存地址 所以为false
        System.out.println(sc == sd);
        //对象 从内存分析
        //布尔值拓展
        boolean flag = true;
        if (flag == true) {
        }//新手
        if (flag) {
        }//老手
        //Less is more!  代码要精简易读
    }
}

posted @ 2021-03-31 22:04  渠立波  阅读(44)  评论(0)    收藏  举报