一、 java基本类型
1.1字符类型:char
1.2布尔类型:boolean
1.3数值类型:byte、short、int、long、float、double
1.3.1整数类型:byte、short、int、long
1.3.2浮点类型:float、double
二、基本类型表示范围
| 类型 | 位数 | 范围 | 最大存储数据量 | 备注 |
|---|
| byte | 8 | -128~127 | 255 | |
| short | 16 | -32768~32767 | 65536 | |
| int | 32 | -2^31 ~ 2^31-1 | 2^32-1 | |
| long | 64 | -2^63 ~ 2^63-1 | 2^64-1 | |
| float | 32 | 3.4e-45~1.4e38 | | 直接赋值必须加F或f |
| double | 64 | 4.9e-324~1.8e308 | | |
| boolean | | true或false | | |
| char | 8 | | | 用单引号赋值 |
三、表示范围包装类
package com.day001;
public class Day001 {
public static void main(String[] args) {
System.out.println("byte长度:"+Byte.SIZE);
System.out.println("byte最小数字:"+Byte.MIN_VALUE);
System.out.println("byte最大数字:"+Byte.MAX_VALUE);
System.out.println("short长度:"+Short.SIZE);
System.out.println("short最小数字:"+Short.MIN_VALUE);
System.out.println("short最大数字:"+Short.MAX_VALUE);
System.out.println("int长度:"+Integer.SIZE);
System.out.println("int最小数字:"+Integer.MIN_VALUE);
System.out.println("int最大数字:"+Integer.MAX_VALUE);
System.out.println("long长度:"+Long.SIZE);
System.out.println("long最小数字:"+Long.MIN_VALUE);
System.out.println("long最大数字:"+Long.MAX_VALUE);
System.out.println("float长度:"+Float.SIZE);
System.out.println("float最小数字:"+Float.MIN_VALUE);
System.out.println("float最大数字:"+Float.MAX_VALUE);
System.out.println("double长度:"+Double.SIZE);
System.out.println("double最小数字:"+Double.MIN_VALUE);
System.out.println("double最大数字:"+Double.MAX_VALUE);
System.out.println("char长度:"+Character.SIZE);
System.out.println("char最小数字:"+Character.MIN_VALUE);
System.out.println("char最大数字:"+Character.MAX_VALUE);
}
}