Java MathincrementExact() Method
Example
Increment different numbers:
System.out.println(Math.incrementExact(12002));System.out.println(Math.incrementExact(18));System.out.println(Math.incrementExact(32));System.out.println(Math.incrementExact(947));Try it Yourself »Definition and Usage
TheincrementExact() method returns 1 more 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 incrementExact(intx)public static long incrementExact(longx)Parameter Values
| Parameter | Description |
|---|---|
| x | Required. An integer to increment from. |
Technical Details
| Returns: | Anint orlong value representing 1 more than an integer. |
|---|---|
| Throws: | ArithmeticException - If the increment causes an overflow. |
| Java version: | 1.8+ |
❮ Math Methods

