逻辑运算符、三元运算符

package operator;

//逻辑运算符
public class Demo01 {
public static void main(String[] args) {
//与(and) 或(or) 非(取反)
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 = 5;
boolean d = (c<4)&&(c++<4); //前面错了不会执行后面的
System.out.println(d);
System.out.println(c);

int m = 5;
boolean n = (m<4)||(++m>5);
System.out.println(n);
System.out.println(m);


}
}



package operator;

public class Demo01 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a+=b; //a = a+b
a-=b; //a = a-b
System.out.println(a);

//字符串连接符
System.out.println(a+b);
System.out.println(""+a+b); //字符串连接符
System.out.println(a+b+"");

//三元运算符
//x ? y : z
//如果x==true,则结果为y,否则结果为z
int score = 80;
String type = score<60 ? "不及格" : "及格";
System.out.println(type);

}
}

(93条消息) Java运算符及运算符的优先级_feifuzeng的博客-CSDN博客_java运算符优先级
posted @   一颗橡皮橙  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示
主题色彩