三元运算符

位运算

package operator;
//位运算================
public class Num6 {
    public static void main(String[] args) {
        /*
        A=0011 1100
        B=0000 1101
​
        A&B=0000 1100
        A|B=0011 1101
        A^B=0011 1101  相同为0 不同则为1 (异或)
        ~B = 1111 0010  取反
​
        2*8=16   2*2*2*2
        << 左移   >> 右移  比如 *2    /2
        0000 0000      0
        0000 0001      1
        0000 0010      2
        0000 0011      3
        0000 0100      4
        0000 1000      8
        0001 0000      16
        */
        System.out.println(2<<3);
    }
}

赋值运算符,字符串连接符

package operator;
​
public class Num7 {
    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类型 后面的运算值也会转换为string类型 如果在后面 则前面的运算正常运算
        System.out.println(""+a+b);//值 :1020
        System.out.println(a+b+"");//值: 30
    }
}
​

三元运算符

package operator;
​
public class Num8 {
    public static void main(String[] args) {
        //三元运算符
            //x? y: z
            // 如果x==true 则结果为y 否则为z
            int score=59;
            String type = score<60?"B":"A";
            System.out.println(type);
    }
}
​
 
posted @ 2022-07-05 15:41  坚持c  阅读(56)  评论(0)    收藏  举报