Alter the signs of various numbers.
System. |
The negateExact() method in Java returns an integer with the same absolute value but the opposite sign of another integer, while handling overflow situations by throwing an exception. This safeguards against inaccuracies that may arise due to overflow.
An overflow typically arises when the integer reaches the minimum value, such as Integer.MIN_VALUE or Long.MIN_VALUE, representing the largest negative integer, as it lacks a positive equivalent.
One of the following:
public
|
|
Parameter |
Description |
X |
Please provide an integer to negate. |
Returns: |
An int or long value representing an integer with an equivalent magnitude but opposite sign to another integer. |
Throws: |
An ArithmeticException is thrown if the negation operation results in an overflow. |
Java Version: |
1.8+ |