Java Math cbrt() Method
The cbrt() method of Math class returns the cube root of a double value.
Syntax:
public static double cbrt(double a)
Parameters:
The parameter ‘a’ represents the value whose cube root is to be determined.
Return Value:
The cbrt () method returns the cube root of the specified value.
- It returns NaN, if we pass a NaN.
- It returns infinity with the same sign as the argument, if we pass a positive infinite argument.
- If we pass zero as an argument, it will return zero with the same sign as the argument.
Example 1:
public class JavaMathCbrtExample1 { public static void main(String[] args) { double a=8.0; //returns the cube root of a double value System.out.println("Cube root of "+ a +" = "+Math.cbrt(a)); } }
Output:
Cube root of 8.0 = 2.0
Example 2:
public class JavaMathCbrtExample2 { public static void main(String[] args) { double a=-0.0d/0.0d; //returns the cube root of a NaN value System.out.println("Cube root of "+ a +" = "+Math.cbrt(a)); } }
Output:
Cube root of NaN = NaN
Example 3:
public class JavaMathCbrtExample3 { public static void main(String[] args) { double a=-0.0; //returns a zero with the same sign as the argument ,if the argument is zero. System.out.println("Cube root of "+ a +" = "+Math.cbrt(a)); } }
Output:
Cube root of -0.0 = -0.0
Example 4:
public class JavaMathCbrtExample4 { public static void main(String[] args) { double a=-5/0.0; //returns infinity with the same sign as the argument ,if the argument is infinity. System.out.println("Cube root of "+ a +" = "+Math.cbrt(a)); } }
Output:
Cube root of -Infinity = -Infinity