其他分享
首页 > 其他分享> > 短路运算+字符串连接符

短路运算+字符串连接符

作者:互联网

短路运算:

public class Annotation {
    public static void main(String[] args) {
        int a = 5;
        boolean b = (a<4)&&(a++<5);//a<4已经成立,a++<5根本不
        //用再算了
        System.out.println(b);
        System.out.println(a);
    }
}

输出结果:

false
5

位运算:

&、|、^、~、<<、>>:

A = 0011 1100

B = 0000 1101

A&B = 0000 1100

A|B = 0011 1101

A^B = 0011 1110

~B = 1111 0010

public class Annotation {
    public static void main(String[] args) {
        int A = 1;
        System.out.println(A<<3);
    }
}

输出:

8

原因:A:0000 0001 左移三位→0000 1000

<<:*2
>>:/2
public class Annotation {
    public static void main(String[] args) {
        int A = 3;
        System.out.println(A<<3);
    }
}

输出:

24

字符串连接符:

public class Annotation {
    public static void main(String[] args) {
        int A = 3;
        int B = 4;
        System.out.println(A+B+"");
        System.out.println(""+A+B);
    }
}

输出:

7
34
public class Annotation {
    public static void main(String[] args) {
        int A = 3;
        int B = 4;
        String type = A>B?"A>B":"A<B";
        System.out.println(type);
    }
}

输出:

A<B

标签:String,int,短路,字符串,static,void,连接符,main,public
来源: https://www.cnblogs.com/Cf030713/p/16155604.html