java的math类pow
数学类静态双战俘(双基,双指数) (Math Class static double pow(double base , double exponent) )
This method is available in java.lang package.
此方法在java.lang包中可用。
This 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.
此方法用于计算给定参数的幂,换句话说,它将第一个参数的值返回为第二个参数的幂。
This is a static method so it is accessible with the class name too.
这是一个静态方法,因此也可以使用类名进行访问。
The return type of this method is double, it returns the power of the given parameters.
此方法的返回类型为double ,它返回给定参数的幂。
In this method, we pass two parameters, and here the first parameter represents the base value and the second parameter represents the exponent value.
在此方法中,我们传递了两个参数,这里的第一个参数代表基值,第二个参数代表指数值。
This method does not throw any exception.
此方法不会引发任何异常。
Syntax:
句法:
public static double pow(double base , double exponent){
}
Parameter(s):
参数:
base – a double value to represent the base.
base –一个代表基数的双精度值。
exponent – a double value to represent the exponent/power.
指数 –代表指数/ 功效的双精度值。
Return value:
返回值:
The return type of this method is double, it returns the base to the power exponent as a result.
此方法的返回类型为double ,结果将底数返回到幂指数。
Note:
注意:
If the base is "NaN" (Not a Number) and the exponent is non-zero), it returns the "NaN".
如果基数是“ NaN”(不是数字)并且指数不为零,则返回“ NaN”。
If the exponent is "NaN", it returns the "NaN".
如果指数是“ NaN”,则返回“ NaN”。
If the exponent value is 1.0, it returns the base value.
如果指数值为1.0,则返回基值。
If the exponent value is 0.0, it returns the 1.0.
如果指数值为0.0,则返回1.0。
If the base is -0.0 and exponent is a finite odd number, it returns the -0.0.
如果基数是-0.0,指数是有限的奇数,则返回-0.0。
If the base is negative infinity and exponent is less than 0 but not a finite odd integer, it returns the 0.0.
如果基数为负无穷大且指数小于0但不是有限的奇数整数,则返回0.0。
If the base is -0 and exponent is a positive finite odd integer, it returns -0.0.
如果基数为-0,指数为正有限奇数整数,则返回-0.0。
If the base negative infinity and exponent is a negative finite odd integer, it returns -0.0.
如果基本负无穷大和指数是负有限奇数整数,则返回-0.0。
If the base is -0 and exponent is less than but not a finite odd integer, it returns the infinity.
如果基数为-0并且指数小于但不是有限的奇数整数,则返回无穷大。
If the base is negative infinity and exponent is greater than 0 but not a finite odd integer, it returns the infinity.
如果基数为负无穷大且指数大于0但不是有限的奇数整数,则返回无穷大。
If the base is negative infinity and exponent is a finite odd integer, it returns the negative infinity.
如果基数为负无穷大且指数为有限奇数整数,则返回负无穷大。
Java程序演示pow(double base,double exponent)方法的示例 (Java program to demonstrate example of pow(double base , double exponent) method)
// Java program to demonstrate the example of
// pow(double base , double exponent) method of Math Class.
public class PowMethod {
public static void main(String[] args) {
// declaring the variables
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("Math.pow(d1,d2): " + Math.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("Math.pow(d3,d4): " + Math.pow(d3, d4));
}
}
Output
输出量
E:\Programs>javac PowMethod.java
E:\Programs>java PowMethod
Math.pow(d1,d2): 8.0
Math.pow(d3,d4): 4096.0
翻译自: https://www.includehelp.com/java/math-class-static-double-pow-double-base-double-exponent-with-example.aspx
java的math类pow