CIS 160 Conditional operator

Objective

  • use the conditional operator (inline selection, ?:)

Conditional operator

  • ?:
  • only ternary operator in Java
  • operates like an inline if/else
  • expr1 ? expr2 : expr3 if expr1 is true, the whole thing is replaced by expr2, otherwise it is replaced by expr3
  • grossPay = hours>40 ? rate*40 + (hours-40)*rate*1.5 : hours*rate;