java数据类型拓展
public class demo2 {
public static void main(String[] args) {
//========================================================
//整数型拓展 进制 二进制 0b 八进制 0 十进制 十六进制 0x
//========================================================
int i1 = 10;
int i2 = 010; //八进制
int i3 = 0x10; //十六进制
int i4 = 0b10; //二进制
System.out.println(i1); //10
System.out.println(i2); //8
System.out.println(i3); //16
System.out.println(i4); //2
System.out.println("=============================");
//========================================================
//浮点型拓展 银行业务怎么表示? 钱
//BigDecimal 数学
//========================================================
//float 有限 离散 舍入误差 大约 接近但不等于
//double
//最好完全避免使用浮点数进行比较
float f1 = 0.1f;
double d = 1.0/10;
System.out.println(f1==d);//false
float f2 = 123123123123123f;
float f3 = f2 + 1;
System.out.println(f2==f3);//true
System.out.println("=============================");
//========================================================
//字符拓展
//========================================================
char c1 = 'a';
char c2 = '中';
System.out.println(c1); //a
System.out.println((int)c1); //97
System.out.println(c2); //中
System.out.println((int)c2); //20013
//所有的字符本质还是数字
//编码 Unicode 表:(97 = a 65 = A) 2字节 0 - 65536 Excel 2^16 = 65536
char c3 = '\u0061';
System.out.println(c3); //a
System.out.println("=============================");
//========================================================
//字符串拓展
//========================================================
String s1 = new String("Hello");
String s2 = new String("Hello");
System.out.println(s1==s2); //false
String s3 = "Hello";
String s4 = "Hello";
System.out.println(s3==s4); //true
System.out.println("=============================");
//========================================================
//boolean拓展
//========================================================
boolean flag = true;
if(flag){}
if(flag==true){}//等价
//转义字符
}
}