数据类型扩展
整数扩展
进制
二进制开头需+0b
十进制
八进制开头需+0
十六进制开头需+0x
int a = 10;
int b = 0b11;
int c = 010;
int d = 0x3;
a = 10,b = 3,c = 8,d = 3
浮点数扩展
浮点数进行对比时尽量不要使用float和double(会有误差)
使用BigDecimal(数据工具类)
强制转换扩展
所有字符本质还是数字(底层原理)
char c1 = 'a';
char c2 = 'A';
System.out.println(c1);
System.out.println((int) c1);
System.out.println(c2);
System.out.println((int) c2);
在这里,int c1 = 97,int c2 = 67
char:Unicode编码,可以处理各种语言文字,占用2个字节
转义字符
\t制表符(空格) \n换行符 等
System.out.println("Hello World");
System.out.println("hello\tWorld");
System.out.println("hello\nWorld");
结果分别是: