Java StrictMath - multiplyExact() Method
The java.lang.StrictMath.multiplyExact() method returns product of its arguments. It throws an exception, if the result overflows an int.
Syntax
public static int multiplyExact(int x, int y)
Parameters
x |
Specify the first value. |
y |
Specify the second value. |
Return Value
Returns product of its arguments.
Exception
Throws ArithmeticException, if the result overflows an int.
Example:
In the example below, multiplyExact() method is used to multiply given numbers.
import java.lang.*; public class MyClass { public static void main(String[] args) { int x = 12; int y = 17; int p = 145; int q = 139; System.out.println(StrictMath.multiplyExact(x, y)); System.out.println(StrictMath.multiplyExact(p, q)); } }
The output of the above code will be:
204 20155
❮ Java.lang - StrictMath