Java Guava | pow(long b, int k) of LongMath Class with Examples
The method pow(long b, int k) of Guava’s LongMath Class returns b to the kth power. Even if the result overflows, it will be equal to BigInteger.valueOf(b).pow(k).longValue(). This implementation runs in O(log k) time.
public static long pow(long b, int 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.
Exception: This method throws IllegalArgumentException if k is negative.
4 to the 5th power is: 1024 12 to the 3rd power is: 1728
java.lang.IllegalArgumentException: exponent (-5) must be >= 0
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.