What is the value displayed by the following program?
public class Main { public static void main(String[] args) { int x = 0;/* ww w . j a v a 2 s . com*/ boolean b1, b2, b3, b4; b1 = b2 = b3 = b4 = true; x = (b1 | b2 & b3 ^ b4) ? x++ : --x; System.out.println(x); } }
B.
From the ternary expression, the value of x must either be 0 or -1.
Because (b1 | b2 & b3 ^ b4) evaluates as (b1 | (b2 & (b3 ^ b4)), the answer is 0.