The java.math.BigDecimal.pow(int n) method is used to calculate a BigDecimal raise to the power of some other positive number passed as parameter (this)n. This method performs raises this BigDecimal number to the power of the positive number passed as the parameter.
public BigDecimal pow(int n)
Parameters: This method accepts a parameter n which is the exponent to which we want to raise the power of BigDecimal number.
Returns: This method returns a BigDecimal which is equal to (this)n.
Exception: The parameter n must be in the range 0 through 999999999, inclusive otherwise ArithmeticException is thrown
Below programs illustrate the pow() method of BigDecimal class
Result of pow operation between BigDecimal 924567 and exponent 5 equal to 675603579456764176151564447607
Result of pow operation between BigDecimal 457863 and exponent 4 equal to 43948311905876729579361
Example 3: Program showing exception when exponent passed as parameter is less than zero.
java.lang.ArithmeticException: Invalid operation
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.