Math.decrementExact()
Java Math.decrementExact() method
Last Updated : 17 Mar 2025
The java.lang.Math.decrementExact() returns the argument decremented by one. It will throw an exception if the result overflows either int or long.
Syntax
Parameter
Return
- If the argument is Integer.MIN_VALUE or Long.MIN_VALUE, it will throw an ArithmeticException.
Example 1
Output:
Example 2
Output:
Example 3
Output:
Exception in thread "main" java.lang.ArithmeticException: integer overflow at java.lang.Math.decrementExact(Math.java:943) at decrementExactExample3.main(decrementExactExample3.java:7)
Example 4
Output:
Exception in thread "main" java.lang.ArithmeticException: long overflow at java.lang.Math.decrementExact(Math.java:960) at decrementExactExample4.main(decrementExactExample4.java:7)