Absolute Value (Ternary, No Math.abs)
Easyjava
Read an integer and print its absolute value using a ternary expression — do not use Math.abs.
Input: one integer.
Output: one line — the absolute value.
Example 1
Input
-7
Output
7
Example 2
Input
5
Output
5
- -1000000000 <= n <= 1000000000
Hint 1
If n is negative, the absolute value is -n; otherwise it is n.
Hint 2
-n uses the unary minus operator.
The ternary picks -n when n is below zero and n otherwise. This is exactly what Math.abs does for integers, written by hand.