Larger Value (Ternary)
Easyjava
Learn the Concept: Ternary OperatorRead two integers and print the larger one using a single ternary expression.
Input: two integers separated by whitespace.
Output: one line — the larger value.
Example 1
Input
5 3
Output
5
Example 2
Input
2 9
Output
9
- -1000000000 <= a, b <= 1000000000
Hint 1
(a > b) ? a : b returns the larger of the two.
Hint 2
When a and b are equal, either branch gives the same value.
The ternary chooses a when a is greater, otherwise b. This replaces a four-line if-else with a single expression.
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Pass or Fail (Ternary)Easy · javaSolve Problem
- Even or Odd (Ternary)Easy · javaSolve Problem
- Absolute Value (Ternary, No Math.abs)Easy · javaSolve Problem