Java Math incrementExact() Method

The incrementExact() method of Math class returns the argument incremented by one, throwing an exception if the result overflows an int or a long.

Syntax:

  1. public static int incrementExact (int a)
  2. public static int incrementExact (long a)

Parameters:

The parameters ‘f1’ and ‘f2’ represent the dividend and the divisor.

Return Value:

The incrementExact () method returns the result after incrementing the argument by one.

Throws:

The incrementExact () method throws:

ArithmeticException – if the result overflows an int or long

Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output: