What does a bitwise exclusive OR do in Java?

后端 未结 4 905
天涯浪人
天涯浪人 2020-12-20 19:18

Given:

public class Spock {
    public static void main(String[] args) {
        Long tail = 2000L;
        Long distance = 1999L;
        Long story = 1000L         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-20 19:44

    It doesn't print anything because when the XOR operator is used with boolean arguments (as opposed to integers) will only return true if exactly one of the 2 operands is true.

    In your first if both parts evaluate to true and true ^ true == false

    In your second if both parts evaluate to false and false ^ false == false

提交回复
热议问题