The pow() method returns the result of the first argument raised to the power of the second argument.
Example
Syntax of Math.pow()
That is, pow(a, b) = ab
The syntax of the pow() method is:
Math.pow(double num1, double num2)
Here, pow() is a static method. Hence, we are accessing the method using the class name, Math.
pow() Parameters
The pow() method takes two parameters.
- num1 - the base parameter
- num2 - the exponent parameter
pow() Return Values
- returns the result of num1num2
- returns 1.0 if num2 is zero
- returns 0.0 if num1 is zero
Note: There are various special cases for the pow() method. To learn about all the special cases, visit Java Math.pow() Special Cases (Official Java Documentation).
Example: Java Math pow()
In the above example, we have used the Math.pow() with positive numbers, negative numbers, zero, and infinity.
Here, Double.POSITIVE_INFINITY is used to implement positive infinity in the program.
Note: When we pass an integer value to the pow() method, it automatically converts the int value to the double value.
int a = 2;
int b = 5;
Math.pow(a, b); // returns 32.0