Advanced Java Decision Making
Advanced Java Decision Making
After covering 'if', 'if-else', 'nested if', and 'switch-case', here are the next decision-making
constructs in Java with examples:
1. Ternary Operator ( ?: )
A shorthand for if-else.
Syntax:
condition ? expression1 : expression2;
Example:
Output:
Eligible to vote
Example:
Output:
1 is Odd
2 is Even
3 is Odd
4 is Even
5 is Odd
Example:
Output:
You can drive
Output:
i=1
i=2
Output:
i=1
i=2
i=4
i=5
Example:
Output:
Weekday