multiplyExact(): This method is available in the Math class of Java.
Syntax:
long java.lang.Math.multiplyExact(long x, int y)
This method takes two arguments, one argument of type long and another of type int as its parameters. This method returns the product of the arguments.
Note:
It throwing an exception if the result overflows a long.
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 a long.
For Example:
Math.multiplyExact(199191,18) = > It returns 3585438.
Approach
Java
public class MultiplyExactLong1 {public static void main(String[] args) {long x = 199191;int y = 18;System.out.println(Math.multiplyExact(x, y));}}
Output:
3585438
No comments:
Post a Comment