San*_*eep -5 java if-statement
我需要解释下面的代码执行
public static void main(String[] args) {
Long tail = 2000L;
Long distance = 1999L;
Long story = 1000L;
if ((tail > distance) ^ ((story * 2) == tail))
System.out.println("a");
if ((distance + 1 != tail) ^ ((story * 2) == distance))
System.out.println("2");
}
Run Code Online (Sandbox Code Playgroud)
代码执行后,不会产生任何输出.
^代表2个布尔运算的XOR运算,如下所示
if ((tail > distance) ^ ((story * 2) == tail))
Run Code Online (Sandbox Code Playgroud)
(tail > distance)是真的
((story * 2) == tail)是真的
并且true XOR true是false