multiplyExact(): This method is available in the Math class of Java.
Syntax:
int java.lang.Math.multiplyExact(int x, int y)
This method takes two arguments of type int as its parameters. This method returns the product of the arguments
Note: It throwing an exception if the result overflows an int.
Parameters: Two parameters are required for this method.
x: the first value.
y: the second value.
Returns: the result
Throws: ArithmeticException - if the result overflows an int.
For Example:
Math.multiplyExact(10,78) = > It returns 780.
Approach
Java
public class MultiplyExactInt {public static void main(String[] args) {int x = 10, y = 78;System.out.println(Math.multiplyExact(x, y));}}
Output:
780
No comments:
Post a Comment