java类型

什么字节

常见面试题
public static void main(String[] args) {
//整数扩展: 进制 二进制0b开头 十进制 八进制0开头 十六进制0x
int i1 = 10;
int i2 = 010;
int i3 = 0x2a;// 0-9 A-F 16
System.out.println(i1);//10
System.out.println(i2);//8 转换成10进制规律是10 = 1*8^1+0*8^0 = 8+0 = 8 (二进制同理)
System.out.println(i3);//42 转换成10进制规律是2a = 2*16^1+10*16^0 = 32+10 = 42
System.out.println("=====================================================");
//浮点数拓展(有限、离散、舍入误差、大约、接近但不等于) 银行业务怎么表示钱?BigDecimal 数学工具类来表示。
float f = 0.1f;
double d = 0.1;
System.out.println(f);//0.1
System.out.println(d);//0.1
System.out.println(f == d);//false
float d1 = 23213546456456456f;
float d2 = d1 + 1;
System.out.println(d1 == d2);//true
System.out.println("===========================================================");
//字符拓展 所有的字符本质还是数字
//编码 Unicode编码表(97 = a 65 = A 包括中文)
char c1 = 'a';
char c2 = '中';
System.out.println(c1);//a
System.out.println((int)c1);//94
System.out.println(c2);//中
System.out.println((int)c2);//20013
//正常unicode编码表示方式
char c3 = '\u0061';
System.out.println(c3);//a
System.out.println("==========================================");
String sc = "hello";
String sd = "hello";
System.out.println(sc == sd);//true
String sa = new String("hello");
String sb = new String("hello");
System.out.println(sa == sb);//false
System.out.println(sa.equals(sb));//true
}

浙公网安备 33010602011771号