本文共 2318 字,大约阅读时间需要 7 分钟。
strictmath
pow() method is available in java.lang package.
pow()方法在java.lang包中可用。
pow() method is used to calculate the power of the given arguments or in other words, it returns the value of the first parameter raised to the power of the second parameter.
pow()方法用于计算给定参数的幂,换句话说,它将第一个参数的值返回为第二个参数的幂。
pow() method is a static method and it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
pow()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出现任何错误。
pow() method does not throw any exception at the time of calculating the power of the given arguments.
pow()方法在计算给定参数的功效时不会引发任何异常。
Syntax:
句法:
public static double pow(double base , double exponent);
Parameter(s):
参数:
base – represents the base.
base –代表基数。
exponent – represents the power (exponent).
指数 –表示幂(指数)。
Return value:
返回值:
The return type of this method is double – it returns the base raised to the power of exponent.
此方法的返回类型为double-将返回的底数返回指数幂。
Note:
注意:
If we pass NaN as the first argument and a non-zero value as the second argument, the method returns NaN.
如果我们将NaN作为第一个参数传递,并将非零值作为第二个参数传递,则该方法将返回NaN。
If we pass NaN as the second argument, the method returns NaN.
如果我们将NaN作为第二个参数传递,则该方法将返回NaN。
If we pass 1.0 as the second argument, the method returns the value of the first argument.
如果我们将1.0作为第二个参数传递,则该方法将返回第一个参数的值。
If we pass 0 (native or positive) as the second argument, the method returns 1.0.
如果我们将0(正数或正数)作为第二个参数传递,则该方法返回1.0。
Example:
例:
// Java program to demonstrate the example of // pow(double base , double exponent) method of StrictMath Class.public class Pow { public static void main(String[] args) { // Variable Declarations double d1 = 2.0; double d2 = 3.0; double d3 = 4.0; double d4 = 6.0; // Here , we will get (d1 raised to the power of d2) // because we are passing parameter (2.0,3.0) System.out.println("StrictMath.pow(d1,d2): " + StrictMath.pow(d1, d2)); // Here , we will get (d3 raised to the power of d4) // because we are passing parameter (4.0,6.0) System.out.println("StrictMath.pow(d3,d4): " + StrictMath.pow(d3, d4)); }}
Output
输出量
StrictMath.pow(d1,d2): 8.0StrictMath.pow(d3,d4): 4096.0
翻译自:
strictmath
转载地址:http://mjvzd.baihongyu.com/