Perform integer subtraction using the subtractExact()
method.
System. |
The subtractExact()
method calculates the difference between two integers, triggering an exception if the operation results in overflow. This safeguard ensures accurate results, particularly when subtracting extremely large negative numbers.
One of the following:
|
|
Parameter |
Description |
x |
“Necessary. The number from which subtraction is performed.” |
y |
“Necessary. The value to be subtracted.” |
Returns: |
An integer or long value representing the result of subtracting two numbers. |
Throws: |
ArithmeticException – If the subtraction operation results in an overflow. |
Java Version: |
1.8+ |