基本数据类型
基本的数据类型可以划分为四大类型:整型,浮点型,字符型,布尔型。
整形: byte(8位), short(16位), int(32位), long(64位)
浮点型: float(单精度。32位), double(双精度。64位)
在数值后面添加F表示float类型,不加默认为表示double类型
如:3.14代表double,3.14F代表float。
字符型: char(16位)
Java中char是16位,也就是占2个字节, C中char是8位,也就是占1个字节。
布尔型: Boolean(1位)
这些数据类型之间也是可以相互转换的:
直接转换:byte——>short——>int——>long——>float——>double 和
char——>int——>long——>float——>double
强制转换:byte<——short<——int<——long<——float<——double 和
char<——int<——long<——float<——double
运算符
算术运算符: +,-,*,/,%,++,–
赋值运算符 =
关系运算符: >,<,>=,<=,==,!= instanceof
public class Test {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println("a == b = " + (a == b) );
System.out.println("a != b = " + (a != b) );
System.out.println("a > b = " + (a > b) );
System.out.println("a < b = " + (a < b) );
System.out.println("b >= a = " + (b >= a) );
System.out.println("b <= a = " + (b <= a) );
}
逻辑运算符: &&,||,!
位运算符: &,|,^,~ , >>,<<,>>>(了解!!!)
条件运算符 ?:
扩展值运算符: +=,-=,*=,/=