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