Home »
Java programming language
Java Math Class static double pow(double base , double exponent) with example
Java Math Class static double pow(double base , double exponent) method: Here, we are going to learn about the static double pow(double base , double exponent) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 06, 2019
Math Class static double pow(double base , double exponent)
- This method is available in java.lang package.
- This method is used to calculate the power of the given arguments or in other words, it returns the value of the first parameter raised to the power of the second parameter.
- This is a static method so it is accessible with the class name too.
- The return type of this method is double, it returns the power of the given parameters.
- In this method, we pass two parameters, and here the first parameter represents the base value and the second parameter represents the exponent value.
- This method does not throw any exception.
Syntax:
public static double pow(double base , double exponent){
}
Parameter(s):
- base – a double value to represent the base.
- exponent – a double value to represent the exponent/power.
Return value:
The return type of this method is double, it returns the base to the power exponent as a result.
Note:
- If the base is "NaN" (Not a Number) and the exponent is non-zero), it returns the "NaN".
- If the exponent is "NaN", it returns the "NaN".
- If the exponent value is 1.0, it returns the base value.
- If the exponent value is 0.0, it returns the 1.0.
- If the base is -0.0 and exponent is a finite odd number, it returns the -0.0.
- If the base is negative infinity and exponent is less than 0 but not a finite odd integer, it returns the 0.0.
- If the base is -0 and exponent is a positive finite odd integer, it returns -0.0.
- If the base negative infinity and exponent is a negative finite odd integer, it returns -0.0.
- If the base is -0 and exponent is less than but not a finite odd integer, it returns the infinity.
- If the base is negative infinity and exponent is greater than 0 but not a finite odd integer, it returns the infinity.
- If the base is negative infinity and exponent is a finite odd integer, it returns the negative infinity.
Java program to demonstrate example of pow(double base , double exponent) method
// Java program to demonstrate the example of
// pow(double base , double exponent) method of Math Class.
public class PowMethod {
public static void main(String[] args) {
// declaring the variables
double d1 = 2.0;
double d2 = 3.0;
double d3 = 4.0;
double d4 = 6.0;
/* Here , we will get (d1 raised to the power of d2)
because we are passing parameter (2.0,3.0)
*/
System.out.println("Math.pow(d1,d2): " + Math.pow(d1, d2));
/* Here , we will get (d3 raised to the power of d4)
because we are passing parameter (4.0,6.0)
*/
System.out.println("Math.pow(d3,d4): " + Math.pow(d3, d4));
}
}
Output
E:\Programs>javac PowMethod.java
E:\Programs>java PowMethod
Math.pow(d1,d2): 8.0
Math.pow(d3,d4): 4096.0