Negate a Number
Easyjava
Learn the Concept: Unary OperatorsRead an integer and print its negation using the unary minus operator.
Input: one integer.
Output: one line — the number with its sign reversed (0 stays 0).
Example 1
Input
5
Output
-5
Example 2
Input
-3
Output
3
- -1000000000 <= n <= 1000000000
Hint 1
Unary minus: -n reverses the sign.
Hint 2
-0 is just 0.
The unary minus operator returns the arithmetic negation of its single operand. Applying it to 0 leaves 0 unchanged.
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Sum 1..N with i++Easy · javaSolve Problem
- Countdown with --Easy · javaSolve Problem
- Pre- vs Post-IncrementMedium · javaSolve Problem