Java Guava | LongMath.checkedPow(long b, int k) method with Examples
checkedPow(long b, long k) is a method of Guava’s LongMath Class which accepts two parameters b and k and is used to find the k-th power of b.
public static long checkedPow(long b, long k)
Parameters: The method accepts two parameters, b and k. The parameter b is called base which is raised to the k-th power.
Return Value: This method returns the k-th power of b.
Exceptions: The method checkedPow(long b, long k) throws ArithmeticException if the k-th power of b overflows in signed long arithmetic.
Below examples illustrate the implementation of the above method:
5 to the 7th power is: 78125 19 to the 4th power is: 130321
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.