代码改变世界

Java数据类型扩展

2021-07-08 15:05  summer的小西瓜  阅读(20)  评论(0)    收藏  举报
import java.math.BigDecimal;

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

        // 浮点数拓展
        // 银行业务怎么表示?
        float f = 0.1F;
        double d = 1.0 / 10;
        System.out.println(d == f); // 返回不一样
        float d1 = 2323232323F;
        float d2 = d1 + 1;
        System.out.println(d1 == d2);

        char c1 = 'a';
        char c2 = '中';
        System.out.println(c1);
        System.out.println((int) c1);
        System.out.println(c2);
        System.out.println((int) c2);
        // 字符的本质还是数字
        // 编码 Unicode 2字节 65536 Excel 2的16次方=65536
        char c3 = '\u0061';
        System.out.println(c3);

        // 转义字符
        // \t 制表符Tab
        // \n 换行
        // ...

        System.out.println("hello\tworld!");
        System.out.println("hello\nworld!");

        String sa = new String("hello,world!");
        String sb = new String("hello,world!");
        System.out.println(sa == sb);

        String sc = "hello,world!";
        String sd = "hello,world!";
        System.out.println(sc == sd);
        // 对象 从内存分析,开辟了2个内存地址
        // 布尔值拓展
        boolean flag = true;
        if (flag) {
            System.out.println("less is more,代码要精简易读");
        }
    }
}