Java基本数据类型
整形
-
byte
byte占用一个字节,-128~127
-
short
short占用2个字节,-36728~36726
-
int
int占用4个字节,范围很大21亿多
-
long
long占用8个字节,范围更大
浮点型
-
float
float占用4个字节
-
double
扫描二维码关注公众号,回复: 13597315 查看本文章double占用8个字节
字符类型
字符类型就一个char,占用2个字节,这里要切记String不是基本类型,很多人初学者会以为String是基本类型里面的字符类型。
Boolean
boolean占用一位字节,它的值只有false,true
idea代码演示
public class text { public static void main(String[] args) { //psvm是主方法的快捷键 byte a=1; short b=2; //byte和short注意不要超过它们的范围了 int c=3; long d=4L; //使用long是,需要在数据后面跟一个大写的L float s=1.111F ; /*使用float时,数据后面也要跟一个大写的F 不过我们一般都是使用double*/ double r=3.1415926535; char tt='q'; //Boolean flag=true; //Boolena flag1=false; System.out.println(a); //sout是输出的快捷键 System.out.println(b); System.out.println(c); System.out.println(d); System.out.println(s); System.out.println(r); System.out.println(tt); } }