English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematical Methods
The Java Math cbrt() method returns the cube root of the specified number.
The syntax of the cbrt() method is:
Math.cbrt(double num)
Note: cbrt() is a static method. Therefore, we can use the class name to access the Math method.
num - The number to calculate the cube root of
Returns the cube root of the specified number
If the specified value is NaN, then return NaN
If the specified number is 0, then return 0
Note: If the parameter is a negative number-num, then 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 a positive number System.out.println(Math.cbrt(value2)); // 3.0 // cubic root of a negative number 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