整数拓展:
二进制0b 例如:int i = 0b10
十进制 例如:int i = 10
八进制0 例如:int i = 010
十六进制0x 例如:int i = 0x10 (0-9 A-F 16)
int num1 = 10;//十进制
int num2 = 0b10;//0b 二进制
int num3 = 010;//0 八进制
int num4 = 0x10;//0x 十六进制
System.out.println(num1);
System.out.println(num2);
System.out.println(num3);
System.out.println(num4);
10
2
8
16
浮点数拓展:
银行业务怎么表示(钱)?
BigDecimal 数学工具类
不使用(float和double)有限、离散、舍入误差、大约、接近但不等于
最好完全避免使用浮点数去比较
float a1 = 0.1f;
double a2 = 0.1;
float a3 = 0.1f;
double a4 = 1.0/10;
System.out.println(a1==a2);
System.out.println(a1==a3);
System.out.println(a2==a4);
System.out.println(a3==a4);
false
true
true
false
字符拓展:
所有的字符本质还是数字
编码 Unicode 可以处以任务语言的文字 占2个字节 0-65536
(会有对应文字的编码表 例如:97=a 65=A)
区间范围:U0000-UFFFF
char a = ‘\u0061’; (’\ '是转义的意思)
system.out.println((int)c1); “(int)是强制转换的意思”
char b1 = 'a';
char b2 = '瓜';
System.out.println(b1);
System.out.println((int)b1);// 强制转换
System.out.println(b2);
System.out.println((int)b2);
char b3 = '\u0055'; // Unicode编码
char b4 = '\u0088';
System.out.println(b3);
System.out.println(b4);
a
97
瓜
29916
U
ˆ
转义字符
\t 制表符
\n 换行
例如:("hello\t"World)
System.out.println("hello\tworld");//转义字符 制表符
System.out.println("hello\nworld");//转义字符 换行
hello world
hello
world
String c1 = new String("helloword" );
String c2 = new String("helloword" );
String c3 = "helloworld";
String c4 = "helloworld";
System.out.println(c1==c2);
System.out.println(c3==c4);
System.out.println(c1==c3);
//对象 从内存分析
false
true
false
布尔值拓展
boolean flag = true;
if(flag==true){}和if(flag){}是一样的
左边是新手用的
boolean d1 = true;
boolean d2 = false;
if (d1==true){
System.out.println("oh my god");
if (d1){
System.out.println("oh my god");
if (d2==false){
System.out.println("apple");
oh my god
oh my god
apple
Less is More 代码要精简易读