JAVA运算符
1.算数运算符
+, -, *, /, %, ++, --
2.关系运算符
>, <, ==, !=, instanceof
3.逻辑运算符
&&, ||, !
4. 位运算符
&, |, ^, -, >>, <<
5. 条件运算符
? :
6. 扩展运算符
+=, -=, *=, /=
package operator;
public class Demo1 {
public static void main(String[] args) {
long a = 12345678912L;
int b = 1234;
short c = 120;
byte d = 6;
System.out.println(a+b+c+d);//计算变量中有long类型,结果为long类型
System.out.println(b+c);//计算结果为int类型
System.out.println(c+d);//计算结果为int类型
System.out.println(a>b);
System.out.println(a%b);
System.out.println(d++);
System.out.println(++c);
System.out.println(Math.pow(2,8));
}
}
逻辑运算符与位运算符
package operator;
public class Demo2 {
public static void main(String[] args) {
boolean a = true;
boolean b = false;
System.out.println("a&&b = " + (a&&b));
System.out.println("a||b = " + (a||b));
System.out.println("!(a&&b) = " + !(a&&b));
int c = 1;
System.out.println(a||((c++)<0)); //短路
System.out.println(c);
int d = 0;
System.out.println(b&&(d++>0));//短路
System.out.println(d);
System.out.println(2<<3);
System.out.println(1024>>4);
int m = 10;
int n = 20;
System.out.println(""+m+n);
System.out.println(m+n+"");
int score = 62;
String type = score<60?"不及格":"及格";
System.out.println(type);
}
}

浙公网安备 33010602011771号