123jgh

导航

 
public class Dome02 {
public static void main(String[] args) {
//逻辑运算符
boolean a = true;
boolean b = false;

System.out.println("a && b:"+(a&&b));//逻辑与运算:两个变量都为真,结果才是true
System.out.println("a || b:"+(a||b));//逻辑或运算:两个变量有一个为真,结果为true
System.out.println("!(a && b:)"+!(a&&b));//如果是true,则结果为false,如果为false则为真
System.out.println("==========================================");

//短路运算
int c = 5;
boolean d = ((c<4)&&(c++<4));//前一个是false则不会执行后一个
System.out.println(d);
System.out.println(c);
System.out.println("==========================================");

/*位运算符
A = 0011 1100
B = 0000 1101
-------------------
A&B = 0000 1100//相对位 全为1 则为1
A|B = 0011 1101//相对位 有1 则为1
A^B = 0011 0001//相对位 相同 则为0
~B = 1111 0010//取反
*/

int e = 10;
int f = 20;

e+=f;//e = e+f
System.out.println(e);
e-=f;//e = e-f
System.out.println(e);

//字符连接串 + String
System.out.println(""+e+f);//先变成string字符串后相连
System.out.println(e+f+"");//先相加后变string字符串
System.out.println("==========================================");

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

}
}
posted on 2022-10-12 16:48  江江要努力  阅读(31)  评论(0)    收藏  举报