Java数据类型拓展

1. int 进制

示例 ↓

int n = 0b10;//二进制 0b开头
int n2 = 010;//八进制 0开头
int n3 = 10;//十进制
int n4 = 0x10;//十六进制 0x开头

输出 ↓

2
8
10
16

2. float

示例 ↓

float f = 23333333f;
float f2 = f + 1;
float f3 = 2333333f;
float f4 = f3 + 1;
System.out.println(f == f2);
System.out.println(f3 == f4);

输出 ↓

true
false

结论 ↓

float有限的离散的,存在 舍入误差大约接近但不等于最好完全避免使用float进行比较


3. char

示例 ↓

char c = 'a';//字母
char c2 = '\u0061';//Unicode转义
char c3 = '一';//中文
System.out.println(c == c2);
System.out.println((int) c);
System.out.println((int) c2);
System.out.println((int) c3);

输出 ↓

true
97
97
19968

结论 ↓

char的本质是数字

posted @ 2021-04-20 15:13  挽风微尘  阅读(48)  评论(0)    收藏  举报