数据类型扩展

 1 public class Demo1 {
 2     public static void main(String[] args) {
 3 //    整数拓展: 进制  二进制0b   十进制     八进制0    十六进制0x
 4         int i=10;
 5         int i2=010;//八进制0
 6         int i3=0x10;//十六进制0x    0~9 A~F 16
 7         System.out.println(i);
 8         System.out.println(i2);
 9         System.out.println(i3);
10         System.out.println("=====================");
11 //      浮点数拓展:银行业务怎么表示?钱
12 //        BigDecimal 数学工具类 算银行的钱
13 //        float 有限 离散 舍入误差 大约 接近但不等于
14 //        double
15 //        最好完全避免使用浮点数进行比较
16 //        最好完全避免使用浮点数进行比较
17 //        最好完全避免使用浮点数进行比较
18         float f=0.1f;//0.1
19         double d=1.0/10;//0.1
20         System.out.println(f==d);//false
21         System.out.println(f);
22         System.out.println(d);
23 
24         float d1 = 123123123123f;
25         float d2 =d1+1;
26         System.out.println(d1==d2);//ture
27 
28 //      字符拓展
29         System.out.println("=====================");
30         char c1='a';
31         char c2='中';
32         System.out.println(c1);
33         System.out.println((int)c1);//强制转换
34 
35         System.out.println(c2);
36         System.out.println((int)c2);//强制转换
37 //      所有的字符本质还是数字
38 //      编码 Unicode 表:(97=a 65=A) 2字节 0-65536  Excel 2 sup 16 =65536
39 
40 //        U000 UFFF
41         System.out.println("=====================");
42         char c3='\u0061';
43         System.out.println(c3);//a
44 
45 //        转义字符
46 //        \t 制表符
47 //        \n 换行
48         System.out.println("=====================");
49         System.out.println("Hello\tWord");
50         System.out.println("Hello\nWord");
51 
52         System.out.println("=====================");
53         String sa =new String("hello word");
54         String sb =new String("hello word");
55         System.out.println(sa==sb);
56 
57         String sc="hello word";
58         String sd="hello word";
59         System.out.println(sc==sd);
60 //        对象 从内存分析
61 
62 //        布尔值扩展
63         boolean flag=true;
64         if (flag==true){ }//新手
65         if (flag){ }//老手
66 //      Less is More! 代码要精简易读
67     }
68 }

 

posted @ 2021-02-02 22:39  奔啵儿灞  阅读(54)  评论(0)    收藏  举报