Languages
[Edit]
EN

Java - Math.pow() method example

0 points
Created by:
ParaEagle
724

Math.pow() is a static method that returns base raised to the power of exponent (value^exponent operation).

public class MathExample {

    public static void main(String[] args) {
        //                            base  exponent
        System.out.println( Math.pow(  1  ,  2       ) ); // 1.0
        System.out.println( Math.pow(  2  ,  2       ) ); // 4.0
        System.out.println( Math.pow(  3  ,  2       ) ); // 9.0

        System.out.println( Math.pow(  0  ,  3       ) ); // 0.0
        System.out.println( Math.pow(  0.5,  0.3     ) ); // 0.8122523963562356
        System.out.println( Math.pow( -1  ,  4       ) ); // 1.0

        System.out.println( Math.pow(  0  , -0.4     ) ); // Infinity
        System.out.println( Math.pow( -0.5, -2       ) ); // 4.0
        System.out.println( Math.pow( -2.0, -2       ) ); // 0.25
        System.out.println( Math.pow(  2.0 , 0.5     ) ); // 1.4142135623730951
    }
}

1. Documentation

Syntax
package java.lang;

public final class Math {

    public static double pow(double base, double exponent) { ... }

}

Note: Classes in the java.lang package are imported automatically, so it is not necessary to do it manually - we use just Math.pow() call.

Parameters

The method takes a double arguments.

  • base - base of power
  • exponent - exponent used with a base
Result

number value (primitive value) calculated as base raised to the power of exponent or NaN if the operation can not be executed.

Descriptionpow is a static method that returns base raised to the power of exponent (value^exponent operation).
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - Math.pow()

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join