![]() |
VOOZH | about |
The java.lang.Math.multiplyExact() is a built-in math function in java that returns the product of the arguments.It throws an exception if the result overflows an int. As multiplyExact(int a, int b) is static, so object creation is not required.
Syntax:
public static int multiplyExact(int a, int b) public static double multiplyExact(int a, double b) Parameter : a : the first value b : the second value Return : This method returns the product of the arguments. Exception : It throws ArithmeticException - if the result overflows an int
Example: To show the working of java.lang.Math.multiplyExact() method.
125 5000
Output:
Runtime Error : Exception in thread "main" java.lang.ArithmeticException: integer overflow at java.lang.Math.multiplyExact(Math.java:867) at Gfg2.main(File.java:13)
Example:
Output:
Overflow occurred.