Java Math.cbrt() method with Examples

Finding the cube root of some given number (Java Math cbrt method)

With this method, we can find the cube root of some given number. So, when we are required to get the cube root of some number, we can make use of the CBRT method. The method takes a number(double value) as an argument and returns the cube root.

The below program is a demonstration of understanding the method for cube root. Remember that this method takes a double number as an argument, and returns the cube root of that double value.

import java.lang.Math;
public class UnderstandingMath {
public static void main(String[] args) {
System.out.println(Math.cbrt(343));
}
}

The output of this program comes out to be 7.0, which is the cube root of the given value.

Special cases –

  • If the input is NaN, the output is NaN.
  • If the argument is infinity, the output is also infinity with the same sign as the argument. (try giving Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY as an argument to the method).
  • If the argument is zero or negative zero, the output is also zero, with the sign preserved.