Java Math.pow() method

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

Syntax

Parameter

Return

This method returns the value of ab

  • If the second argument is positive or negative Zero, this method will return 1.0.
  • If the second argument is not a number (NaN), this method will return NaN.
  • If the second argument is 1, this method will return the result same as the first argument.

Example 1

public class PowExample1
{
    public static void main(String[] args) 
    {
        double x = 5;
        double y = 4;
        //returns 5 power of 4 i.e. 5*5*5*5
        System.out.println(Math.pow(x, y));
    }
}
Test it Now

Output:

625.0

Example 2

public class PowExample2
{
    public static void main(String[] args) 
    {
        double x = 9.0;
        double y = -3;
        //return (9) power of -3
        System.out.println(Math.pow(x, y));
    }
}
Test it Now

Output:

0.0013717421124828531

Example 3

Test it Now

Output:

NaN

Example 4

Test it Now

Output:

3.5461138422596736

Next TopicJava Math




Latest Courses