整数、字符、布尔值拓展

 1 package base;
 2 
 3 public class Demo03 {
 4     public static void main(String[] args) {
 5         // 整数拓展: 进制    十进制
 6 
 7         int i1 = 10;
 8         int i2 = 0b10; //二进制0b
 9         int i3 = 010;  //八进制0
10         int i4 = 0x10; //十六进制0x
11         System.out.println(i1);
12         System.out.println(i2);
13         System.out.println(i3);
14         System.out.println(i4);
15         System.out.println("=====================================");
16         //浮点数拓展 银行业务怎么表示?
17         //BigDecimal 数学工具类
18 
19         //float 有限 离散 舍入误差 大约 接近但不等于
20         //double
21         //最好完全避免使用浮点数进行比较
22 
23         float f = 0.1f;
24         double d = 1.0 / 10;
25 
26         System.out.println(f);
27         System.out.println(d);
28         System.out.println(f == d);
29 
30         float d1 = 34234234242342f;
31         float d2 = d1 + 1;
32 
33         System.out.println(d1 == d2);
34         System.out.println("=====================================");
35 
36         //字符拓展
37 
38         char c1 = 'a';
39         char c2 = '辰';
40 
41         System.out.println(c1);
42         System.out.println((int) c1);
43         System.out.println(c2);
44         System.out.println((int) c2);
45 
46         //所有的字符本质还是数字
47         //编码 Unicode 表:(a = 97  A = 65) 2字节   0 - 65536
48         //U0000 UFFFF
49 
50         char c3 = '\u0061';
51         System.out.println(c3);//a
52 
53         //转义字符
54         // \t 水平制表符
55         // \n 换行
56         //...
57 
58         System.out.println("Hello\nWorld");
59         System.out.println("=====================================");
60 
61         String s1 = new String("hello world");
62         String s2 = new String("hello world");
63         String s3 = "hello world";
64         String s4 = "hello world";
65         System.out.println(s1 == s2);
66         System.out.println(s3 == s4);
67         //对象 从内存分析
68 
69         //布尔值扩展
70         boolean flag = true;
71         if (flag == true) {
72 
73         } //新手
74         if (flag) {
75 
76         } //老手
77         //less is more! 代码要精简易读
78 
79     }
80 }

 

posted @ 2021-02-22 16:45  浅小墨  阅读(86)  评论(0)    收藏  举报