1. 程式人生 > 其它 >IntelliJ IDEA 啟用碼,啟用IDEA之後的有效期是99年

IntelliJ IDEA 啟用碼,啟用IDEA之後的有效期是99年

package operator;
public class Demo5 {
//與 或 非
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));//真變假,假變真

    //短路運算,//前面c<4為錯,後面不執行
    int c =5;
    boolean d = (c<4)&&(c++<4);
    System.out.println(d);
    System.out.println(c);
}

}

package operator;

public class Demo6 {
public static void main(String[] args) {
/*
A= 0011 1100
B= 0000 1101
--------------------
A&B = 0000 1100 //A與B,兩個都為1是1,兩個都為0是0,否則為0
A|B = 0011 1101 //A或者B,都是0為0都是1為1,其中一個是1就是1
A^B = 0011 0001 //取反,相同為0,否則為1
~B = 1111 0010//取反,取B的反

    2*8位運算非常的快,效率高
    <<  >> 指向哪邊往哪邊移
    左移相當於*2,右移相當於/2
    0000 0000 0
    0000 0001 1
    0000 0010 2
    0000 0011 3
    0000 0100 4
    0000 1000 8
     */
    System.out.println(2<<3);
}

}

package operator;

public class Demo7 {
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);

    //字串連線符 +  ""string字串
    System.out.println(a+b);
    System.out.println(""+a+b);
    System.out.println(a+b+"");//字串在後面不運算
}

}

package operator;
//三元運算子
public class Demo8 {
public static void main(String[] args) {
// X? Y:Z
//X為真,則輸出Y,否則輸出Z

    int score = 80;
    String type = score < 60 ? "不及格":"及格";
    // if
    System.out.println(type);

}

}