运算符![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/905f6a154c16c4c71663ad4974b58b08.jpeg)
1.二元运算符(算数运算符):
package com.beiming.base;
public class Demo01 {
public static void main(String[] args) {
int a,b;
a=10;
b=20;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/b);
System.out.println(a%b);
System.out.println((double) a/b);
}
}
30
-10
200
0
10
0.5
2.不同类型的运算
package com.beiming.base;
public class Demo02 {
public static void main(String[] args) {
long a=55L;
float b=5.4f;
int c=128;
byte d=8;
short e=7;
System.out.println(a+b);
System.out.println(a+c+d+e);
System.out.println(c+d);
System.out.println(d+e);
}
}
3.关系运算符
package com.beiming.base;
public class Demo03 {
public static void main(String[] args) {
int a=10;
int b=20;
System.out.println(a<b);
System.out.println(a>b);
System.out.println(a=b);
System.out.println(a!=b);
}
}
true
false
20
false
4.自增 自减 一元运算符
package com.beiming.base;
public class Demo04 {
public static void main(String[] args) {
int a=3;
int c=3;
int b=a++;
int d=++c;
double pow = Math.pow(2, 3);
System.out.println(b);
System.out.println(d);
System.out.println(pow);
}
}
3
4
8.0
5.逻辑运算符
package com.beiming.base;
public class Demo05 {
public static void main(String[] args) {
boolean a=true;
boolean b=false;
System.out.println(a&&b);
System.out.println(a||b);
System.out.println(!(a&&b));
int c=5;
boolean d=(c<5)&&(c++<10);
System.out.println(c);
}
}
false
true
true
5
6.位运算符
package com.beiming.base;
public class Demo06 {
public static void main(String[] args) {
System.out.println(2<<3);
}
}
16
7.字符串连接符
package com.beiming.base;
public class Demo07 {
public static void main(String[] args) {
int a=10;
int b=20;
System.out.println(a+b);
System.out.println(""+a+b);
}
}
30
1020
8.三元运算符
package com.beiming.base;
public class Demo08 {
public static void main(String[] args) {
int x=90;
System.out.println(x<60?"不及格":"及格");
}
}