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 Next Article Java Math addExact(int a, int b) method 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 List add(int index, E element) method in Java The add(int index, E ele) method of List interface in Java is used to insert the specified element at the given index in the current list. Implementation:Java// Java code to illustrate add(int index, E elements) import java.util.*; public class ArrayListDemo { public static void main(String[] args) 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 Math floorDiv() method in Java The Math.floorDiv() is a built-in math function in Java that returns the largest (closest to negative infinity) integer value that is less than or equal to the algebraic quotient of two numbers. As floorDiv() is static, object creation is not required. The floorDiv() method performs division that ro 3 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 BigInteger andNot() Method in Java The java.math.BigInteger.andNot(BigInteger val) method returns a BigInteger whose value is (this & ~val) where this to the current BigInteger with which the function is being used and val is the bigInteger passed to the function as a parameter. This method, which is equivalent to and(val.not()), 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 Math fma() method in Java with Examples In Math class, there are two types of fma() method depending upon the parameters passed to it. The methods are: fma(double a, double b, double c): This method of Math class is used to return the exact product of the first two doubles with the addition of the third double and then round the result to 5 min read Like