Java的数据类型分为两大类
基本类型
整数类型
整数类型
byte:占1个字节
?范围:-128~127
short:占2个字节
?范围:-32768~32767
int:占4个字节
?范围:-2147483648~2147483647
long:占8个字节
?范围:-9223372036854775808~9223372036854775807
浮点类型
float:占4个字节
double:占8个字节
字符类型
char:占2个字节
boolean类型:占1位
true
false
public class BaseDataType{
public static void main(String[] args) {
//整数
//byte 范围:-128~127
byte b = 127;
//short 范围:-32768~32767
short s = 32767;
//int 范围:-2147483648~2147483647
//int最常用
int i = 2147483647;
//long 范围:-9223372036854775808~9223372036854775807
//long类型要在数字后面加L
long l = 9223372036854775807L;
//浮点型
//float 在数字后要加F
float f = 101.1F;
//double
double d = 1000303.9;
//字符
//char
char c = ‘a‘;
//字符串
//String
String str = "String不是关键字,是类";
//boolean
boolean b1 = true;
boolean b2 = false;
//输出
System.out.println("byte = " + b);
System.out.println("short = " + s);
System.out.println("int = " + i);
System.out.println("long = " + l);
System.out.println("float = " + f);
System.out.println("double = " + d);
System.out.println("char = " + c);
System.out.println("String = " + str);
System.out.println("boolean = " + b1);
System.out.println("boolean = " + b2);
}
}
引用类型
类
接口
数组