public class SumType {
public static void main(String[] args) {
/**
* 布尔类型
* 1 字节
*/
boolean bool = false;// 默认
boolean bool2 = true;
System.out.println("bool = " + bool);
System.out.println("bool2 = " + bool2);
System.out.println("----------------------------------");
/**
* byte类型
* 1 字节
* 范围 [-128 0 127] (2^7 0 2^7-1)
*/
byte b1 = -128;
byte b0= 0;// 默认
byte b2 =127;
System.out.println("b0 = " + b0);
System.out.println("b1 = " + b1);
System.out.println("b2 = " + b2);
System.out.println("----------------------------------");
/**
* 字符类型
* 2 字节
* 范围 [\u0000 \uffff] (0 65535) 2^16 (无符号整数)
*/
char ch =97;
char ch1 = 'a';
System.out.println("ch = " + ch);
System.out.println("ch1 = " + ch1);
System.out.println("----------------------------------");
/**
* 短整数类型
* 2 字节
* 范围[-32768 32767] (-2^15 2^15-1)
*/
short s1 = -32768;
short s0 = 0;// 默认
short s3 = 32767;
System.out.println("s1 = " + s1);
System.out.println("s0 = " + s0);
System.out.println("s3 = " + s3);
System.out.println("----------------------------------");
/**
* 整数类型
* 4 字节
* 范围 正负 21 亿左右 (-2^31 2^31-1)
*/
int i1 = -2147483648 ;
int i0 = 0;// 默认
int i2 = 2147483647;
System.out.println("i0 = " + i0);
System.out.println("i1 = " + i1);
System.out.println("i2 = " + i2);
System.out.println("----------------------------------");
/**
* 长整数类型
* 8 字节
* 范围 (-2^63 2^63)
*/
long l1 = -9223372036854775808L;
long l0 = 0L;// 默认
long l2 = 9223372036854775807L;
System.out.println("l0 = " + l0);
System.out.println("l1 = " + l1);
System.out.println("l2 = " + l2);
System.out.println("----------------------------------");
/**
* 单精度浮点类型
* 4 字节
* -3.4E+38 ~ 3.4E+38 之间
* 有效数字 6-7
*/
float f = 0.0f;// 默认
System.out.println("f = " + f);
System.out.println("----------------------------------");
/**
* 双精度浮点类型
* 8 字节
* 有效数字15-16
*/
double d = 0.0;// 默认
System.out.println("d = " + d);
}
Java 基本数据类型
最新推荐文章于 2021-06-09 13:55:03 发布