EN
Java - Math.pow() method example
0 points
Math.pow()
is a static method that returns base raised to the power of exponent (value^exponent
operation).
xxxxxxxxxx
1
public class MathExample {
2
3
public static void main(String[] args) {
4
// base exponent
5
System.out.println( Math.pow( 1 , 2 ) ); // 1.0
6
System.out.println( Math.pow( 2 , 2 ) ); // 4.0
7
System.out.println( Math.pow( 3 , 2 ) ); // 9.0
8
9
System.out.println( Math.pow( 0 , 3 ) ); // 0.0
10
System.out.println( Math.pow( 0.5, 0.3 ) ); // 0.8122523963562356
11
System.out.println( Math.pow( -1 , 4 ) ); // 1.0
12
13
System.out.println( Math.pow( 0 , -0.4 ) ); // Infinity
14
System.out.println( Math.pow( -0.5, -2 ) ); // 4.0
15
System.out.println( Math.pow( -2.0, -2 ) ); // 0.25
16
System.out.println( Math.pow( 2.0 , 0.5 ) ); // 1.4142135623730951
17
}
18
}
Syntax |
xxxxxxxxxx 1 package java.lang; 2 3 public final class Math { 4 5 public static double pow(double base, double exponent) { ... } 6 7 }
|
Parameters |
The method takes a double arguments.
|
Result |
|
Description | pow is a static method that returns base raised to the power of exponent (value^exponent operation). |