JAVA整数扩展,浮点数扩展,字符串扩展,进制等问题,面积基础必

2020-04-28  本文已影响0人  司徒新新

整数扩展 进制 二进制 0B 十进制 八进制0 十六进制0x

        int i = 10;
        int i2 = 010;  //八进制0
        int i3 = 0x10;  //十六进制 0x   0~9  A-F  16
        System.out.println(i);
        System.out.println(i2);
        System.out.println(i3);

输出结果

10
8
16

浮点数扩展

BigDecimal 数字工具类 可使用
float 有限 离散 舍入误差 大约 接近单不等于
double
!最好完全避免使用浮点数去比较
!最好完全避免使用浮点数去比较
!最好完全避免使用浮点数去比较
~~重要的事情说三遍

        float f = 0.1f;
        double d = 1.0 / 10;
        System.out.println(f == d);
        System.out.println(f);
        System.out.println(d);

        float d1 = 23343432143432343214f;
        float d2 = d1 + 1;
        System.out.println(d1 == d2);

输出结果

false
0.1
0.1
true

字符串扩展

        char c1 = 'a';
        char c2 = '中';

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

        //所有的字符本质还是数字
        //编码 Unicode表: (97 = a   65 = A)   2个字节           以前 最多可表示 65536个字符  Excel最长只有2的16次方  就等于 65536

        char c3 = '\u0061';
        System.out.println(c3);

输出结果

a
97
中
20013
a

转义字符

        System.out.println("xin\txin");

输出结果

xin xin

字符串比较

        String sa = new String("hello world");
        String sbb = new String("hello world");
        System.out.println(sa == sbb);

        String sc = "hello world";
        String sd = "hello world";
        System.out.println(sc == sd);

输出结果

false
true
上一篇 下一篇

猜你喜欢

热点阅读