Java Math decrementExact() Method
Example
Decrement different numbers:
System.out.println(Math.decrementExact(12002));
System.out.println(Math.decrementExact(18));
System.out.println(Math.decrementExact(32));
System.out.println(Math.decrementExact(947));
Try it Yourself »
Definition and Usage
The decrementExact()
method returns 1 less than
a specified integer and throws an exception if an overflow occurs. This prevents incorrect results that can occur from the overflow.
Syntax
One of the following:
public static int decrementExact(int x)
public static long decrementExact(long x)
Parameter Values
Parameter | Description |
---|---|
x | Required. An integer to decrement from. |
Technical Details
Returns: | An int or long value representing 1 less than an integer. |
---|---|
Throws: | ArithmeticException - If the decrement causes an overflow. |
Java version: | 1.8+ |
❮ Math Methods