Java基础04:数据类型拓展及面试题
-
整数拓展
进制
二进制(0b),十进制,八进制(0),十六进制(0x)
public class Demo01{
public static void main(String[] args){
int i = 10; //十进制
int i1 = 010; //八进制
int i2 = 0x10; //十六进制
System.out.println(i);
System.out.println(i1);
System.out.println(i2);
}
}
-
浮点数拓展
有限 离散 舍入误差 大约 接近但不等于
最好完全避免用浮点数进行比较Bigdecimal 数学工具类
float f = 0.1f;
double d = 1.0/10;
判断 fd 输出false
float d1 = 3.2f;
float d2 =d1+1;
判断 d1> d2 输出true -
字符拓展
char c1 = 'a';
char c2 = '中';
System.out.println(c1);
System.out.println((int)c1); //输出97
System.out.println(c2);
System.out.println((int)c2); //输出20013
所有字符本质上还是数字
-
Uncode 编码 2个字节 65536
String sa = new String( original:" HelloWorld");
String sb = new String( original:" HelloWorld");
System.out.println(sa == sb); //输出falseString sc = " HelloWorld";
String sd = " HelloWorld";
System.out.println(sc == sd); //输出true
对象 内存分析 -
转义字符
\t 制表符
\n 换行 -
布尔值扩展
boolean flag = true;
if ( flag = true){}
if ( flag ){}
//Less is More 代码精简易读