Given:
public class Spock {
public static void main(String[] args) {
Long tail = 2000L;
Long distance = 1999L;
Long story = 1000L;
if ((tail > distance) ^ ((story * 2) == tail)) {
System.out.print("1");
}
if ((distance + 1 != tail) ^ ((story * 2) == distance)) {
System.out.print("2");
}
}
}
Why this sample code doesn't output anything?
In first if you get true ^ true = false
In second if you get false ^ false = false
becouse ^
- is OR exclusive
opeartor, it's means
true ^ true = false
true ^ false = true
false ^ true = true
false ^ false = false