strictmath
StrictMath類cbrt()方法 (StrictMath Class cbrt() method)
cbrt() method is available in java.lang package.
cbrt()方法在java.lang包中可用。
cbrt() method is used to find the cube root of the given parameter in the method. Here, cbrt stands for cube root.
cbrt()方法用于查找方法中給定參數的立方根。 在這里, cbrt代表cube root 。
cbrt() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
cbrt()方法是一個靜態方法,因此可以使用類名進行訪問,如果嘗試使用類對象訪問該方法,則不會收到錯誤。
In this method, if we pass a 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).
在此方法中,如果傳遞正參數,則返回給定參數的立方根(正);否則,傳遞負參數,使它返回給定參數的立方根(負) 。
cbrt() method does not throw any exception.
cbrt()方法不會引發任何異常。
Syntax:
句法:
public static double cbrt(double d);
Parameter(s):
參數:
double d – represents a double type value whose cube root to be found.
double d –表示要查找其立方根的double類型值。
Return value:
返回值:
The return type of this method is double – it returns the cube root of given angle.
此方法的返回類型為double-返回給定角度的立方根。
Note:
注意:
If we pass NaN as an argument, method returns the same value (NaN).
如果我們將NaN作為參數傳遞,則方法將返回相同的值(NaN)。
If we pass zero (0), method returns the same value with the same sign.
如果傳遞零(0),則方法將返回具有相同符號的相同值。
If we pass an infinity, method returns the same value with the same sign.
如果我們傳遞一個無窮大,則方法將返回帶有相同符號的相同值。
Example:
例:
// Java program to demonstrate the example
// of cbrt(double d) method of StrictMath Class.
public class Cbrt {
public static void main(String[] args) {
// variable declarations
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("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
System.out.println("d5: " + d5);
System.out.println("d6: " + d6);
// Here , we will get (-0.0) because we are
// passing parameter (-0.0) so the cube root is the same
System.out.println("StrictMath.cbrt(d1): " + StrictMath.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("StrictMath.cbrt(d2): " + StrictMath.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("StrictMath.cbrt(d3): " + StrictMath.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("StrictMath.cbrt(d4): " + StrictMath.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("StrictMath.cbrt(d5): " + StrictMath.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("StrictMath.cbrt(d6): " + StrictMath.cbrt(d6));
}
}
Output
輸出量
d1: -0.0
d2: 0.0
d3: -Infinity
d4: Infinity
d5: 1000.0
d6: -1000.0
StrictMath.cbrt(d1): -0.0
StrictMath.cbrt(d2): 0.0
StrictMath.cbrt(d3): -Infinity
StrictMath.cbrt(d4): Infinity
StrictMath.cbrt(d5): 10.0
StrictMath.cbrt(d6): -10.0
翻譯自: https://www.includehelp.com/java/strictmath-cbrt-method-with-example.aspx
strictmath