Even or Odd (Ternary)
Easyjava
Learn the Concept: Ternary OperatorRead an integer and print Even or Odd using the ternary operator.
Input: one integer.
Output: one line — Even or Odd.
Example 1
Input
4
Output
Even
Example 2
Input
7
Output
Odd
- -1000000000 <= n <= 1000000000
Hint 1
n % 2 == 0 tests for even.
Hint 2
Negative even numbers also give remainder 0.
n % 2 == 0 is the condition; the ternary returns "Even" when it holds and "Odd" otherwise. Zero is even, and the sign does not matter.
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Pass or Fail (Ternary)Easy · javaSolve Problem
- Larger Value (Ternary)Easy · javaSolve Problem
- Absolute Value (Ternary, No Math.abs)Easy · javaSolve Problem