八大基本类型、字节、位、字符
八大基本类型
| byte | short | int | long | float | double | char | boolean | |
|---|---|---|---|---|---|---|---|---|
| 字节 | 1 | 2 | 4 | 8 | 4 | 8 | 2 | 1位 |
进制
int a=10;
int b=010; //0开头:八进制
int c=0x10; //0x开头:十六进制
System.out.print(a); //输出10
System.out.print(b); //输出8
System.out.print(c); //输出16
float、double
float:有限、离散、舍入误差、大约数、接近但不等于
最好完全使用浮点数进行比较
另:银行业务中的钱使用BigDecimal 数学工具类来表示
float f=0.1f; //0.1
double d=1.0/10; //0.1
System.out.print(f==d); //false
float f1=231231231231231f;
float f2=f1+1;
System.out.print(f1==f2); //true
char字符
char c='a';
char c2='中';
System.out.print(c); //
System.out.print((int)c); //97
System.out.print(c2); //
System.out.print((int)c2); //20013
注:所有的字符本质上还是数字
字节、位、字符
- 位(bit):计算机内存数据存储的最小单位。
- 字节(byte):是计算机中数据处理的基本单位,通常用大写B来表示,范围:-128~127。
- 字符:指计算机中使用的数字、字母、符号和字。
1(byte,字节)=8b(bit,位)
1024B=1KB
1024KB=1M
1024M=1G

浙公网安备 33010602011771号