java.lang.StrictMath.pow()是StrictMath类的一种内置方法,用于查找幂值,即,一个自变量的值升为另一自变量的幂。数学上是指
。它产生三个特殊结果:
当一个参数为NaN而另一个为非零参数或NaN时,该方法返回NaN。
当第二个参数为1.0时,该方法返回与第一个参数相同的值。
当第二个参数为正零或负零时,该方法返回1.0。
用法:
public static double pow(double num1, double num2)
参数:该方法接受两个参数:
num1:这是双精度类型,是指基数。
num2:这是双精度类型,是指 index 。
返回值:该方法返回操作num1^num2的值。
例子:
Input:num1 = 6
num2 = 4
Output:1296.0
Input:num1 = 5
num2 = 2
Output:25.0
下面的程序演示了java.lang.StrictMath.pow()方法:
程序1:
// Java praogram to illustrate the
// java.lang.StrictMath.pow()
import java.lang.*;
public class Geeks {
public static void main(String[] args)
{
double num1 = 12, num2 = 6;
// It returns num1 to the power num2
double pow_Value = StrictMath.pow(num1, num2);
System.out.print(num1 + " to the power of " +
num2 + " = ");
System.out.println(pow_Value);
double pow_Value1 = StrictMath.pow(num1, 0);
double pow_Value2 = StrictMath.pow(num1, 0);
System.out.println(num1+" raised to the"+
" power 0 = " + pow_Value1);
System.out.println(num2+" raised to the"+
" power 0 = " + pow_Value2);
}
}
输出:
12.0 to the power of 6.0 = 2985984.0
12.0 raised to the power 0 = 1.0
6.0 raised to the power 0 = 1.0
程序2:
// Java praogram to illustrate the
// java.lang.StrictMath.pow()
import java.lang.*;
public class Geeks {
public static void main(String[] args)
{
double num1 = 4.7, num2 = 2.5;
// It returns num1 to the power num2
double pow_Value = StrictMath.pow(num1, num2);
System.out.print(num1 + " to the power of " +
num2 + " = ");
System.out.println(pow_Value);
}
}
输出:
4.7 to the power of 2.5 = 47.88997880559147