Java Math cbrt()

The syntax of the cbrt() method is:

Math.cbrt(double num)

Here, cbrt() is a static method. Hence, we are accessing the method using the class name, Math.


cbrt() Parameters

The cbrt() method takes a single parameter.

  • num - number whose cube root is to be computed

cbrt() Return Values

  • returns cube root of the specified number
  • returns NaN if the specified value is NaN
  • returns 0 if the specified number is 0

Note: If the argument is negative number -num, then cbrt(-num) = -cbrt(num).


Example: Java Math cbrt()

In the above example, we have used the Math.cbrt() method to compute the cube root of infinity, positive number, negative number, and zero.

Here, Double.POSITIVE_INFINITY is used to implement positive infinity in the program.

When we pass an integer value to the cbrt() method, it automatically converts the int value to the double value.

int a = 125;

Math.cbrt(a);   // returns 5.0

Recommended Tutorials