Logical operation, short-circuit operations, bit operations, exponentiation

//幂运算.  很多运算会使用工具类来运算
        double pow = Math.pow(2,3);
        System.out.println(pow);

        //逻辑运算符
        // 与 或 非
        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)); //如果是真,则变为假,如果是假,则变为真

        //短路运算 假如 a&&b 的运算中,a是false,那边不会计算后一个变量,这叫短路运算
        int g = 5;
        boolean h = (g<4)&&(g++<4);
        System.out.println(h);
        System.out.println(g);

        //  << = *2;  >> = /2;
Released six original articles · won praise 0 · Views 112

Guess you like

Origin blog.csdn.net/Progutenberg/article/details/104104447