English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematische Methoden
Java Math cbrt()方法返回指定数字的立方根。
cbrt()方法的语法为:
Math.cbrt(double num)
注意:cbrt()是静态方法。因此,我们可以使用类名来访问该方法Math。
num - 要计算其立方根的数字
返回指定数字的立方根
如果指定值为NaN,则返回NaN
如果指定的数字为0,则返回0
注意:如果参数为负数-num,则cbrt(-num) = -cbrt(num).
class Main { public static void main(String[] args) { // Erstellen Sie eine Double-Variable double value1 = Double.POSITIVE_INFINITY; double value2 = 27.0; double value3 = -64; double value4 = 0.0; // Kubikwurzel von Unendlich System.out.println(Math.cbrt(value1)); // Unendlich // Kubikwurzel von Positive Zahlen System.out.println(Math.cbrt(value2)); // 3.0 // Kubikwurzel von Negative Zahlen System.out.println(Math.cbrt(value3)); // -4.0 // Kubikwurzel von Null System.out.println(Math.cbrt(value4)); // 0.0 } }
In dem obigen Beispiel haben wir die Math.cbrt()-Methode verwendet, umUnendlich,Positive Zahlen,Negative ZahlenundNullKubikwurzel.
Hier wird Double.POSITIVE_INFINITY verwendet, um im Programm eine positive Unendlichkeit zu implementieren.
Wenn wir einen int-Wert an die cbrt()-Methode übergeben, wandelt sie diesen int-Wert automatisch in einen double-Wert um.
int a = 125; Math.cbrt(a); // Zurück 5.0