java中cbrt
数学类静态double cbrt(double d) (Math Class static double cbrt(double d))
This method is available in java.lang package.
此方法在java.lang包中可用。
This method is used to find the cube root of the given parameter in the method.
此方法用于查找方法中给定参数的立方根。
In this method, cbrt stands for cube root.
在此方法中,cbrt代表多维数据集根。
This is a static method so this method is accessible with the class name too.
这是一个静态方法,因此也可以使用类名访问此方法。
The return type of this method is double that means it returns the cube root of the given parameter which is of the double datatype.
此方法的返回类型为double,这意味着它返回给定参数的多维数据集根,该参数为double数据类型。
In this method, we pass only one parameter as an argument in the method of Math class and pass only the parameter for which we have to find the cube root.
在此方法中,我们仅将一个参数作为参数传递给Math类的方法,并且仅传递必须为其找到立方根的参数。
In this method, if we pass positive parameter so it returns the cube root of the given parameter with the same sign(Positive) else if we pass negative parameter so it returns the cube root of the given parameter with the same sign(Negative).
在此方法中,如果传递正参数,则返回给定参数的立方根(正);否则,传递负参数,使它返回给定参数的立方根(负)。
This method does not throw any exception.
此方法不会引发任何异常。
Syntax:
句法:
public static double cbrt(double d){
}
Parameter(s):
参数:
double d – A double value whose cube root to be found.
double d-一个双精度值,将找到其立方根。
Note:
注意:
If we pass "NaN", it returns "NaN".
如果我们传递“ NaN”,则返回“ NaN”。
If we pass zero (-0 or 0), it returns the same value.
如果我们传递零(-0或0),它将返回相同的值。
If we pass an infinity, it returns the same value i.e. an infinity.
如果我们传递一个无穷大,它将返回相同的值,即无穷大。
Return value:
返回值:
The return type of this method is double, it returns the cube root of the given value.
此方法的返回类型为double ,它返回给定值的立方根。
Java程序演示cbrt(double d)方法的示例 (Java program to demonstrate example of cbrt(double d) method)
// Java program to demonstrate the example of cbrt(double d)
// method of Math Class
class CbrtMethod {
public static void main(String[] args) {
// Here we are declaring few variables
double d1 = -0.0;
double d2 = 0.0;
double d3 = -7.0 / 0.0;
double d4 = 7.0 / 0.0;
double d5 = 1000.0;
double d6 = -1000.0;
// Display previous value of d1,d2,d3,d4,d5 and d6
System.out.println("Old value of d1 before implementation is :" + d1);
System.out.println("Old value of d2 before implementation is :" + d2);
System.out.println("Old value of d3 before implementation is :" + d3);
System.out.println("Old value of d4 before implementation is :" + d4);
System.out.println("Old value of d5 before implementation is :" + d5);
System.out.println("Old value of d6 before implementation is :" + d6);
// Here, we will get (-0.0) because we are passing parameter
// (-0.0) so the cube root is the same
System.out.println("New value of d1 after implementation is :" + Math.cbrt(d1));
// Here, we will get (0.0) because we are passing parameter
// (0.0) so the cube root is the same
System.out.println("New value of d2 after implementation is :" + Math.cbrt(d2));
// Here, we will get (-Infinity) because we are passing parameter
// (-7.0/0.0) so the cube root is (-Infinity)
System.out.println("New value of d3 after implementation is :" + Math.cbrt(d3));
// Here, we will get (Infinity) because we are passing parameter
// (7.0/0.0) so the cube root is (Infinity)
System.out.println("New value of d4 after implementation is :" + Math.cbrt(d4));
// Here, we will get (10.0) because we are passing parameter
// (1000.0) so the cube root is 10.0
System.out.println("New value of d5 after implementation is :" + Math.cbrt(d5));
// Here, we will get (-10.0) because we are passing parameter
// (-1000.0) so the cube root is (-10.0)
System.out.println("New value of d6 after implementation is :" + Math.cbrt(d6));
}
}
Output
输出量
E:\Programs>javac CbrtMethod.java
E:\Programs>java CbrtMethod
Old value of d1 before implementation is :-0.0
Old value of d2 before implementation is :0.0
Old value of d3 before implementation is :-Infinity
Old value of d4 before implementation is :Infinity
Old value of d5 before implementation is :1000.0
Old value of d6 before implementation is :-1000.0
New value of d1 after implementation is :-0.0
New value of d2 after implementation is :0.0
New value of d3 after implementation is :-Infinity
New value of d4 after implementation is :Infinity
New value of d5 after implementation is :10.0
New value of d6 after implementation is :-10.0
翻译自: https://www.includehelp.com/java/math-class-static-double-cbrt-double-d-with-example.aspx
java中cbrt