package operator;
public class Demo01 {
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((double)a/b);
System.out.println(c%a); //模运算(取余运算)
//关系运算符
System.out.println(a>b);
System.out.println(a<b);
System.out.println(a==b);
//++ -- 自增 自减
int e = a++;
int g = ++a;
int h = --a;
int f = a--;
System.out.println(e);
System.out.println(f);
System.out.println(g);
System.out.println(h);
//逻辑运算符 与(&&) 或(||) 非(!)
boolean i = true;
boolean j =false;
System.out.println("i && j:"+(i && j));//逻辑与运算 有假则假 全真则真
System.out.println("i || j:"+(i || j));//逻辑或运算 有真则真 全假则假
System.out.println("!(i && j):"+!(i && j));//假为真 真为假
//字符串连接符 + String
System.out.println(""+a+b); //1020
System.out.println(a+b+""); //30
//三元运算符
//x ? y : z
//如果x==true,则结果为y,否则为z
int score = 90;
String type = score <60 ? "不及格" : "及格";
System.out.println(type);
}
}
[运算符学习视频:B站狂神说Java](https://www.bilibili.com/video/BV12J41137hu?p=27)
java运算符
最新推荐文章于 2023-11-21 09:50:00 发布