Java基础语法篇-demo08

public class demo08 {
    
    
    public static void main(String[] args) {
    
    
        /**
         * A=   1010 0011
         * B=   1100 0101
         * A&B= 1000 0001
         * A|B= 1110 0111
         * A^B= 0110 0110   异或
         * ~B=  0011 1010
         *
         *位运算符 效率高,速度快,底层运算
         *
         * << 左移    *2
         * >> 右移    /2
         */
        System.out.println(2<<3);//0000 0010 (2)--->  0001 0000(16)
        System.out.println(2>>3);
        System.out.println("======================");
        /**
         *
         * 三元运算符
         * +=,-=         *
         */
        int a=10;
        int b=20;
        a+=b;
        System.out.println(a);//30
        a-=b;
        System.out.println(a);//10
        /**
         * string 字符串连接
         */
        int c=11;
        int d=22;
        System.out.println(c+d+"");//33
        System.out.println(""+c+d);//1122
        System.out.println("========================");
        /**
         * 三元运算符
         * x ? y : z;
         *如果x==true,则结果为y;否则,结果为z
         */
        int score=90;
        String result=score < 60 ? "不及格":"及格";
        System.out.println(result);
    }
}

猜你喜欢

转载自blog.csdn.net/QianXunZhe23/article/details/115220732
今日推荐