数据类型
- java是强类型语言,所有变量都必须先定义后才能使用
java的数据类型分为两大类
- 基本类型(primitive type)
- 整数型
- byte 占1个字节 范围:-128-127
- short 占2个字节 范围:-32768-32767
- int 占4个字节 范围:-2147483648-2147483647
- long 占8个字节 范围:-9223372036854775808-9223372036854775807
- 浮点型
- 布尔类型
- 字符型
- 引用类型(reference type)
- 类(String)
- 接口
- 数组
byte num1 = 10;
short num2 = 20;
int num3 = 30;
long num4 = 40L;
float num5 = 50.1F;
double num6 = 3.1415926;
boolean flag = true;
char i = 'A';
String name = "国家";
整数拓展(进制)
int i = 10;
int i2 = 010;
int i3 = 0x16;
System.out.println(i);
System.out.println(i2);
System.out.println(i3);
浮点数拓展
float f1 = 0.1F;
double f2 = 1.0/10;
System.out.println(f1==f2);
System.out.println(f1);
System.out.println(f2);
float f3 = 2312315656123132131f;
double f4 = f3 + 1;
System.out.println(f3 == f4);
System.out.println(f3);
System.out.println(f4);
转义字符拓展
System.out.println("Hello\tWorld");
System.out.println("Hello\nWorld");
System.out.println("Hello\'World");
System.out.println("Hello\\World");
布尔类型拓展
boolean b1 = true;
if (b1==true){
System.out.println(b1);
}
if(b1){
System.out.println(b1);
}