八种基本数据类型
整数类型
- byte 占一个字节
- short 占两个字节
- int 占四个字节
- long 占八个字节
浮点数类型
- float 占四个字节
- double 占八个字节
字符类型
char 占两个字节(在c语言中占一个字节)
可能有的人认为string也是字符类型,但其实string不是基本数据类型,String是一个对象
布尔类型
- boolean 占一个字节(true或者false)
package Test1;
public class BianDeom {
/*
注意定义long类型变量的时候要加上L或l
注意定义float类型变量的时候要加上F或f
*/
public static void main(String[] args) {
//定义byte类型
byte b = 10;
System.out.print(b);
System.out.print("\r");
//定义short类型
short s = 9;
System.out.print(s);
System.out.print("\r");
//定义int类型
int i = 8;
System.out.println(i);
//定义long类型
long l =10000L;
System.out.println(l);
//定义float类型
float f = 3.14F;
System.out.println(f);
//定义double类型
double d = 3.14;
System.out.println(d);
//定义char类型
char c = 'a';
System.out.println(c);
//定义boolean类型
boolean bl = true;
System.out.println(bl);
}
}