Java基本数据类型扩展
整数扩展
int i = 10;
int i2 = 010;
int i2 = 0x10;
System.out.println(i);
System.out.println(i1);
System.out.println(i2);
输出

即1-9开头为十进制,0开头为八进制,0x开头为16进制。
浮点数扩展
float f = 0.1f;//0.1
double d = 1.0 / 10;//0.1
System.out.println(f == d);
System.out.println(f);
System.out.println(d);
float d1 = 1316546153164651321f;
float d2 = d1 + 1;
System.out.println(d1 == d2) ;
输出

即最好不用浮点型进行对比
字符扩展
char c1 = 'a';
char c2 = '中';
System.out.println(c1);
System.out.println((int) c1);//强制转换
System.out.println(c2);
System.out.println((int) c2);//强制转换
//所有字符本质还是数字
//编码 UNicode 表:(97 = a 65 = A) 2字节 0-65536 Excel 2 16 = 65536
//U0000 - UFFFF
char c3 = '\u0061';
System.out.println(c3);//a
//转义字符
// \t 制表符
// \n 换行
//···
System.out.println("Hello\tworld");
System.out.println("========================");
String sa = new String("hello world");
String sb = new String("hello world");
System.out.println(sa == sb);
String sc = "hello world";
String sd = "hello world";
System.out.println(sc == sd);
//对象 从内存分析
输出

布尔值扩展
boolean flag = true;
if (flag == true) {}
if (flag) {}
含义相同的语句描述越少越好
本文介绍了Java中的基本数据类型,包括整数(int)的十进制、八进制和十六进制表示,浮点数(float和double)的精度问题,字符(char)的Unicode编码以及字符串(String)和布尔(boolean)的使用。强调了在比较时浮点数的不精确性以及对象与基本类型的差异。

被折叠的 条评论
为什么被折叠?



