Home >>Java Math Methods >Java Math.pow() Method

Java Math.pow() Method

Java Math.pow() Method

The Math.pow() method in Java Method is used to return to the power of the second argument the first argument value raised. The method return type pow() is double.

Syntax

public static double pow(double a, double b)  

Parameters

a= This parameter is used for a base

b= This parameter is used for a exponent

Returns

This method is used to returns the value of ab

  1. This method will return 1.0 if the second statement is positive or negative Zero.
  2. If the second argument is not a number (NaN), then NaN is returned by this method.
  3. If the second argument is 1 this method returns the same result as the first argument.

Java Math.pow() Method Example 1


public class MyClass 
{  
    public static void main(String[] args)   
    {  
        double a = 4;  
        double b = 6;  
        System.out.println(Math.pow(a, b));  
    }  
}  

Output:
4096.0

Java Math.pow() Method Example 2


public class MyClass
{  
    public static void main(String[] args)   
    {  
        double a = 4.0;  
        double b = -2;  
        System.out.println(Math.pow(a, b));  
    }  
} 

Output:
0.0625