算数运算符
package operator;
public class Demo01 {
public static void main(String[] args) {
int a = 10;
int b = 20;
int c = 25;
int d = 25;
System.out.println(a/b);
System.out.println(a/(double)b);
}
}
>0 >0.5
自增运算符,幂运算符
package operator;
public class Demo02 {
public static void main(String[] args) {
//自增运算
int a = 3;
int b = a++;
//b=a ; a=a+1
//a=a+1
//c=a
int c = ++a;
System.out.println(a);
System.out.println(b);
System.out.println(c);
//幂运算
double pow = Math.pow(2,3);
System.out.println(pow);
}
}
>5 >3 >5 >8.0
逻辑运算符、短路运算符
| && | 与 |
|---|---|
| || | 或 |
| ! | 非 |
package operator;
public class Demo03 {
public static void main(String[] args) {
//短路运算
int c = 5;
boolean d = (c<4)&&(c++<4);//如果前面判断是错误后面计算机不会执行。如下:
System.out.println(d);
System.out.println(c);
}
}
>false >5
位运算符
package operator;
public class Demo04 {
public static void main(String[] args) {
System.out.println(2<<3);
}
}
>16
字符串拼接
package operator;
public class Demo05 {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(" "+a+b);
System.out.println(a+b+" ");
}
}
> 1020 >30
条件运算符
package operator;
public class Demo06 {
public static void main(String[] args) {
int score = 80;
String s = score > 70 ? "及格" : "不及格";
System.out.println(s);
}
}
>及格



