In Java XOR with three true inputs returns true. Why?

前端 未结 7 1010
一个人的身影
一个人的身影 2021-02-08 00:42

The following code

System.out.println(\"1 0 0: \" + (true ^ false ^ false));
System.out.println(\"1 0 1: \" + (true ^ false ^ true));
System.out.println(\"1 1 0:         


        
7条回答
  •  天涯浪人
    2021-02-08 01:25

    Think about how the compiler evaluates this:

    (true ^ true) ^ true
    

    After first term true ^ true, which is false, has been evaluated:

    (false) ^ true ==> true
    

提交回复
热议问题