Java Math incrementExact() Method Last Updated : 09 May, 2025 Comments Improve Suggest changes Like Article Like Report The incrementExact() is a built-in function in Java provided by the Math class, which returns the argument incremented by one. It throws an exception if the result overflows the specified datatype, either long or int, depending on which data type has been used on the method argument.This method is helpful when we work with values near the maximum or minimum limits of integer types.Syntax of incrementExact() Methodint Math.incrementExact(int num)long Math.incrementExact(long num)Parameter: num: The number we want to increment.Returns: It returns the value num + 1, unless it causes an overflow.Exception Throws: It throws an ArithmeticException if the increment overflows the data type range.Examples of Java Math incrementExact() MethodExample 1: In this example, we will see the basic usage of incrementExact() method. Java // Java program to show how incrementExact() works import java.lang.Math; public class Geeks { public static void main(String[] args) { int a = 12; int b = -3; System.out.println(Math.incrementExact(a)); System.out.println(Math.incrementExact(b)); } } Output13 -2 Explanation: Here in this example, the values 12 and -3 are safely incremented by 1. Here no exception is thrown because they are within the valid range for integers.Example 2: In this example, we will see what happens in the case of overflow. Java // Java program to demonstrate // overflow with incrementExact() import java.lang.Math; public class Geeks { public static void main(String[] args) { int max = Integer.MAX_VALUE; // This will throw ArithmeticException System.out.println(Math.incrementExact(max)); } } Output:Exception in thread "main" java.lang.ArithmeticException: integer overflowExplanation: Here in this example, the value of Integer.MAX_VALUE is 2147483647. When we try to increment it goes beyond the int range, which throws an exception. This is useful to avoid silent overflow bugs.When Should We Use incrementExact() Method?We should use this method when we perform any arithmetic operations where overflow matters.In financial or large calculations where silent overflow could cause major issues.To catch bugs during development where values grow continuously.Important Points:It works with both int and long types.It is safer than using num + 1 in financial or large calculations. Comment More infoAdvertise with us Next Article Java Math decrementExact() method G gopaldave Follow Improve Article Tags : Misc Java Java-lang package java-math Practice Tags : JavaMisc Similar Reads Java Math incrementExact() method The incrementExact() is a built-in function in Java provided by the Math class, which returns the argument incremented by one. It throws an exception if the result overflows the specified datatype, either long or int, depending on which data type has been used on the method argument.This method is h 2 min read Java Math decrementExact() method The java.strictmath.lang.decrementExact() is a built-in function in java which returns the argument decremented by one, throwing an exception if the result overflows the specified datatype either long or int depending on which data type has been used on the method argument. Since this is decrement, 2 min read Java Math incrementExact(int x) method The java.lang.Math.incrementExact() is a built-in math function in java which returns the argument incremented by one.It throws an exception if the result overflows an int.As incrementExact(int x) is static, so object creation is not required. Syntax : public static int incrementExact(int x) Paramet 1 min read LongAdder decrement() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.decrement() is an inbuilt method in java that reduces the value by 1. Syntax: public void decrement() Parameters: The function does not accepts any parameter. Return value: The method do not returns any value 2 min read LongAdder increment() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.increment() is an inbuilt method in java that increases the value by 1. Syntax: public void increment() Parameters: The function does not accepts any parameter. Return value: The method do not returns any val 2 min read Java HashMap computeIfPresent() Method In Java, the computeIfPresent() method of the HashMap class is used to compute a new value for a specified key if the key is already present in the map and its value is not null. If the key is not present, no action is taken.Example 1: In this example, the computeIfPresent() method updates the value 3 min read Like