📜  带有示例的Java cbrt() 方法

📅  最后修改于: 2022-05-13 01:55:37.860000             🧑  作者: Mango

带有示例的Java cbrt() 方法

Java.lang.Math.cbrt()方法返回双精度值的立方根。
笔记:

  • 负值立方根是该值大小的立方根负数
  • 如果参数是NaN ,那么结果NaN
  • 如果参数是无限的,则结果是与参数相同符号无穷大
  • 如果参数为零,则结果为零,其符号与参数相同

句法 :

public static double cbrt(double a)
Parameter :
a : an argument
Return :
This method returns the cube root of a.

示例:显示Java.lang.Math.cbrt()方法的工作。

// Java program to demonstrate working
// of java.lang.Math.cbrt() method
import java.lang.Math;
  
class Gfg {
  
    // driver code
    public static void main(String args[])
    {
        double a = 125.0;
        double b = 1.0 / 0;
        double c = -(1.0 / 0);
        double d = 0.0;
        double e = -0.0;
  
        System.out.println(Math.cbrt(a));
  
        // Input Positive Infinity
        // Output Positive Infinity
        System.out.println(Math.cbrt(b));
  
        // Input Negative Infinity
        // Output Negative Infinity
        System.out.println(Math.cbrt(c));
  
        // Input Positive Zero
        // Output Positive Zero
        System.out.println(Math.cbrt(d));
  
        // Input Negative Zero
        // Output Negative Zero
        System.out.println(Math.cbrt(e));
    }
}

输出:

5.0
Infinity
-Infinity
0.0
-0.0