Java Guava | LongMath.checkedMultiply(int a, int b) method with Examples
The checkedMultiply(long a, long b) is a method of Guava’s LongMath Class which accepts two parameters a and b, and returns their product.
public static long checkedMultiply(long a, long b)
Parameters: The method accepts two long values a and b and computes their product.
Return Value: The method returns the product of long values passed to it, provided it does not overflow.
Exceptions: The method checkedMultiply(long a, long b) throws ArithmeticException if the product i.e, (a – b) overflows in signed long arithmetic.
Below examples illustrate the implementation of above method:
Product of 25 and 36 is: 900 Product of 150 and 667 is: 100050
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.