English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math mathematical methods
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) { // Create a double variable double value1 = Double.POSITIVE_INFINITY; double value2 = 27.0; double value3 = -64; double value4 = 0.0; // cubic root of infinity System.out.println(Math.cbrt(value1)); // Infinity // cubic root of positive numbers System.out.println(Math.cbrt(value2)); // 3.0 // cubic root of negative numbers System.out.println(Math.cbrt(value3)); // -4.0 // cubic root of zero System.out.println(Math.cbrt(value4)); // 0.0 } }
In the above example, we used the Math.cbrt() method to calculateinfinity,positive numbers,negative numbersandzerocubic root.
Here, Double.POSITIVE_INFINITY is used to implement positive infinity in the program.
When we pass an int value to the cbrt() method, it automatically converts the int value to the double value.
int a = 125; Math.cbrt(a); // Return 5.0