3.6-Making Decisions with the Ternary Operator Flashcards

1
Q

What is the Conditional operator (a.k.a Ternary operator)?

A

booleanExpression ? expressionWhenTrue: expressionWhenFalse

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Ternary Operator PITFALL?

A

If the result value is assigned, both expressionWhenTrue and expressionWhenFalse should be from the same type.
✅ System.out.println(1 == 1 ? 5 : “different”);
❌ int ternary = (1 == 1 ? 5 : “different”); //WONT COMPILE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly