if Statements and Control Flow

AP Computer Science A· difficulty 3/5

What is <code>int max = (a > b) ? a : b;</code> equivalent to?

  • A

    max = (a == b);

  • B

    if (a < b) max = a; else max = b;

  • C

    max = a + b;

  • D

    if (a > b) max = a; else max = b;

    check_circle

Explanation

Ternary <code>cond ? trueVal : falseVal</code> is shorthand for if-else.

Want 10 more like this — adaptive to your weak spots?

Related questions