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
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