運算子(二)
邏輯運算子
package operator;
//邏輯運算子
public class Demo05 {
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);
}
}
左移右移
package operator;
public class Demo06 {
public static void main(String[] args) {
//2*8 如何運算最快
//<< *2
//>> /2
//和最底層打交道,左移右移是最快的
System.out.println(2<<3);
}
}
package operator;
public class Demo07 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a+=b;
a-=b;
//字串連接符 + ,string
System.out.println(""+a+b);
System.out.println(a+b+"");
}
}
三元運算子
package operator;
public class Demo08 {
public static void main(String[] args) {
int score = 80;
String type = score <60 ? "不及格" : "及格";
System.out.println(type);
}
}
優先級

點擊跳轉到遇見狂神說視頻教程
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/246103.html
標籤:其他
