Java pow() 方法

Java Number类Java Number类


pow() 方法 返回第一个参数的第二个参数次方

语法

double pow(double base, double exponent)

参数

  • base -- 任何原生数据类型。

  • exponent -- 任何原生数据类型。

返回值

返回第一个参数的第二个参数次方

pow.java

public class pow{
    public static void main(String args[]){
        double x = 2;
        double y = 3;
        System.out.printf("e value is %.4f%n", Math.E);
        System.out.printf("pow(%.3f, %.3f) is %.3f%n", x, y, Math.pow(x, y));
    }
}

编译以上程序,输出结果为:

e value is 2.7183
pow(2.000, 3.000) is 8.000

Java Number类Java Number类