Java Math addExact(int a, int b) method Last Updated : 31 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The java.lang.Math.addExact() is a built-in math function in java which returns the sum of its arguments. It throws an exception if the result overflows an int.As addExact(int a, int b) is static, so object creation is not required. Syntax : public static int addExact(int a, int b) Parameter : a : the first value b : the second value Return : This method returns the sum of its arguments. Exception : It throws ArithmeticException - if the result overflows an int Example :To show working of java.lang.Math.addExact() method. java // Java program to demonstrate working // of java.lang.Math.addExact() method import java.lang.Math; class Gfg1 { // driver code public static void main(String args[]) { int a = 100; int b = 200; System.out.println(Math.addExact(a, b)); } } Output: 300 java // Java program to demonstrate working // of java.lang.Math.addExact() method import java.lang.Math; class Gfg2 { // driver code public static void main(String args[]) { int x = Integer.MAX_VALUE; int y = 200; System.out.println(Math.addExact(x, y)); } } Output: Runtime Error : Exception in thread "main" java.lang.ArithmeticException: integer overflow at java.lang.Math.addExact(Math.java:790) at Gfg2.main(File.java:13) Comment More infoAdvertise with us N Niraj_Pandey Follow Improve Article Tags : Java DSA Java-lang package java-math Practice Tags : Java Similar Reads Java Math subtractExact(int a , int b) method The subtractExact() is a built-in function in Java provided by the Math class. This method returns the difference of the arguments. It throws an exception if the result overflows an int or long data type. As subtractExact() is static, so object creation is not required.This method helps detect overf 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 BigInteger and() Method in Java The java.math.BigInteger.and(BigInteger val) method returns a BigInteger whose value is bitwise-AND of two BigIntegers. This method returns a negative number if both of the BigIntegers are negative. The and() method applies bitwise-AND operation upon the current bigInteger and bigInteger passed as p 2 min read Java Math addExact(long x, long y) method The java.lang.Math.addExact() is a built-in math function in java which returns the sum of its arguments. It throws an exception if the result overflows a long.As addExact(long x, long y) is static, so object creation is not required. Syntax : public static long addExact(long x, long y) Parameter : 1 min read java.math class and its methods | Set 1 Math class provides mathematical functions to perform basic numeric operations such as exponential, logarithm, square root, and trigonometric functions. cosh, sin, tan, abs, bitLength, multiply and many more. Implementations of the functions of Math class do not return bit-for-bit same results. Henc 4 min read Like