The Java pow Function is one of the Java Math Library function and it is used to calculate the Power of the specified expression. In this article we will show you, How to write Math.pow function in Java Programming language with example.

## Java pow Function syntax

The basic syntax of the Math.pow Function in Java Programming language is as shown below:

1 2 3 4 |
static double pow(double base, double Exponent); // Return Type is Double //In order to use in Java program use following code Math.pow(double base, double Exponent); |

**Base:**Please specify the base value here.**Exponent:**Please specify the Exponent value or power here.

For example, if **x** is base value and **2** is exponent then, Math.pow (x, 2) = x²

The Java Math.pow function will return the *Base value* raised to the power of *Exponent value*. There are some special case where the result will be different and they are:

- If the
*Exponent value*is positive or negative zero, Math.pow will return the result as**1.**.*0* - If either the
*Base value*or*Exponent value*argument is not a Number, Java Math.pow will return the result as.*NaN* - If the Absolute value of the
*Base value*is equal to 1 and the*Exponent value*is infinity, then Math.pow will return the result as.*NaN* - If
- the Absolute value of the
*Base value*is greater than 1 and the*Exponent value*is positive infinity, or - the Absolute value of the
*Base value*is less than 1 and the*Exponent value*is negative infinity, then the result is.**Positive Infinity**

- the Absolute value of the
- If
- the Absolute value of the
*Base value*is greater than 1 and the*Exponent value*is negative infinity, or - the Absolute value of the
*Base value*is less than 1 and the*Exponent value*is positive infinity, then the result is.**Positive Zero**

- the Absolute value of the
- If
- the
*Base value*is positive zero and the*Exponent value*is greater than zero, or - the
*Base value*is positive infinity and the*Exponent value*is less than zero, then the result is.**Positive Zero**

- the
- If
- the
*Base value*is positive zero and the*Exponent value*is less than zero, or - the
*Base value*is positive infinity and the*Exponent value*is greater than zero, then the result is.**Positive Infinity**

- the
- If
- the
*Base value*is negative zero and the*Exponent value*is greater than zero but not a finite odd integer, or - the
*Base value*is negative infinity and the*Exponent value*is less than zero but not a finite odd integer, then Java Math.pow will return the result is.**Positive Zero**

- the
- If
- the
*Base value*is negative zero and the*Exponent value*is positive finite odd integer, or - the
*Base value*is negative infinity and the*Exponent value*is negative finite odd integer, then the result is.**Negative Zero**

- the
- If
- the
*Base value*is negative zero and the*Exponent value*is less than zero but not a finite odd integer, or - the
*Base value*is negative infinity and the*Exponent value*is greater than zero but not a finite odd integer, then the result is.**Positive Infinity**

- the
- If
- the
*Base value*is negative zero and the*Exponent value*is negative finite odd integer, or - the
*Base value*is negative infinity and the*Exponent value*is positive finite odd integer,then Java Math.pow will return the result is.**Negative Infinity**

- the
- If the
*Base value*is finite & less than zero and- if the
*Exponent value*is a finite even integer, the result is equal to the result of raising the absolute value of the*Base value*to the power of the*Exponent value* - if the
*Exponent value*is a finite odd integer, the result is equal to the negative of result of raising the absolute value of the*Base value*to the power of the*Exponent value* - if the
*Exponent value*is finite and not an integer, then Java Math.pow will return the result is.**NaN**

- if the

## Java pow Function Example

The Java Math.pow function is used to return the Power of the given number. In this example, We are going to find the power of both positive and negative double values and display the output

**JAVA CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
//Java Math.pow Function package MathFunctions; public class PowMethod { public static void main(String[] args) { double a = Math.pow((5.12 - 4.65 + 3.53), 3); System.out.println("Math.Expm1 Result = = " + a); System.out.println("\nMath.pow Result for Zero as Second argument = " + Math.pow(2, 0)); System.out.println("Math.pow Result for Zero as First argument = " + Math.pow(0, 2)); System.out.println("\nMath.pow Result of Positive Number = " + Math.pow(2, 3)); System.out.println("Math.pow Result of Positive Number = " + Math.pow(4, 2)); System.out.println("\nMath.pow Result of Negative Number = " + Math.pow(-2, 3)); System.out.println("Math.pow Result of Negative Number = " + Math.pow(3, -4)); } } |

**OUTPUT**

**ANALYSIS**

First, We declared variable **a** of type Double and used the Java Math.pow function directly on expression. Here, we used * System.out.println* statement to print the result as output.

1 2 |
double a = Math.pow((5.12 - 4.65 + 3.53), 3); System.out.println("Math.Expm1 Result = = " + a); |

From the above statement, Math.pow((5.12 – 4.65 + 3.53), 3) ==> Math.pow(4, 3) ==> 64

Next, We used the Math.pow Function with one positive double value and other argument as zero.

1 2 |
System.out.println("\nMath.pow Result for Zero as Second argument = " + Math.pow(2, 0)); System.out.println("Math.pow Result for Zero as First argument = " + Math.pow(0, 2)); |

Next, We used the Math.pow Function directly on Positive double values.

1 2 |
System.out.println("\nMath.pow Result of Positive Number = " + Math.pow(2, 3)); System.out.println("Math.pow Result of Positive Number = " + Math.pow(4, 2)); |

Next, We used the Math.pow Function directly on Negative double values.

1 2 |
System.out.println("\nMath.pow Result of Negative Number = " + Math.pow(-2, 3)); System.out.println("Math.pow Result of Negative Number = " + Math.pow(3, -4)); |

Thank You for Visiting Our Blog

IPL 2016 says

After checking out a number of the blog articles on your site, I honestly appreciate your

way of blogging. I book-marked it to my bookmark website list and will be checking back soon. Take a look

at my web site as well and let me know your opinion.