运算符
- 算术运算符 + - * / % ++ - -
- 赋值运算符=
- 关系运算符> < >= <= == != instanceof
- 逻辑运算符&& || !
- 位运算符& | ^ ~ >> << >>>
- 条件运算符? :
- 扩展运算符+= - = *= /=
算术运算符
package operator;
import base.*;
public class Demo1 {
public static void main(String[] args) {
int a = 10;
int b = 20;
int c = 30;
int d = 40;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/(double)b);//类型转换
}
}
package operator;
public class Demo2 {
public static void main(String[] args) {
long a = 1212123123123L;
int b = 141;
short c = 16;
byte d = 8;
System.out.println(a+b+c+d);//Long
System.out.println(b+c+d);//int
System.out.println(c+d);//int
System.out.println(c+d);
}
}
关系运算符:返回结果为布尔值