基本运算符
基本运算符
1、算术运算符:+ ,-, *, /, %, ++, --
2、赋值运算符 =
3、关系运算符 > , < , >= , <= , == , != , instanceof
4、逻辑运算符 && , || , !
以上需熟练
5、位运算符 & , ^ , ~ , >> , << , >>>(了解即可)
6、条件运算符 ? :
7、扩展赋值运算符 += , -= , *= , /=
package operator;
public class demo01 {
public static void main(String[] args) {
//二元运算符
//Ctrl + d 复制当前行到下一行
int a = 10;
int b = 20;
int c = 25;
int d = 25;
System.out.println(a + b);
System.out.println(a - b);
System.out.println(a * b);
System.out.println(a / b);
System.out.println(a / (double)b);
System.out.println((double)a / b);
System.out.println((double)(a / b));
long aa = 1234567890L;
int bb = 123;
short cc = 10;
byte dd = 8;
System.out.println(aa + bb + cc + dd);
System.out.println(bb + cc + dd);
System.out.println(cc + dd);
//关系运算符,正确,错误,结果为布尔值
int a1 = 10;
int a2 = 20;
int a3 = 23;
System.out.println(a3 % a2);//模运算,23/20=1....3
System.out.println(a1 > a2);
System.out.println(a1 < a2);
System.out.println(a1 == a2);
System.out.println(a1 != a2);
}
}