Java – Find Cube Root – cbrt() Method – Examples & Explanation

`java.lang.Math.cbrt()` method is used to find the cube root of a double value in JAVA for the given input (`x` – parameter).
For positive finite x, cbrt(-x) == -cbrt(x); that is, the cube root of a negative value is the negative of the cube root of that value’s magnitude.
The computed result must be within 1 ulp of the exact result.

`cbrt()` method exists in `Math` class of `java.lang` package.
Since: JDK1.5

Declaration of `cbrt()` Method

The declaration of `cbrt()` method is:

Syntax of `cbrt()` Method

The syntax of `cbrt()` method in Java is:

Example

Output:
` 3.0 `
Example
By importing `java.lang` package the syntax of `cbrt()` method can be used as:

Output:
` -0.3 `

Parameters of `cbrt()` Method in Java

`x` – Where `x` is any valid double input value. This parameter is required.

Error Handling

If the `x` parameter is not a number `cbrt()` method returns an `error`.
If there is no argument (`x` – input value) passes to the method, the compiler will produce an `error`.Example

Output:
`Error`

Return Value of `cbrt()` Method in Java

`cbrt()` method returns the cube root of a double value for the given input (`x` – parameter).

Java `cbrt()` Method Example 1

Output:
` cube root of a Negative Value: -2.6622548577813987 cube root of a Positive Value: 4.497941445275415 cube root of Zero: 0.0 `

Java `cbrt()` Method Example 2

Output:
` 5.643803094122362E102 1.7031839360032603E-108 NaN -10.072802033522548 3.499782299384434E-4 2.5637980732444143 0.0 -1.3715339700741747 -923.8750385410053 `

Special Cases of `cbrt()` Method in Java

If the argument is NaN, then the result is NaN.
If the argument is infinite, then the result is an infinity with the same sign as the argument.
If the argument is zero, then the result is a zero with the same sign as the argument.
Example

Output:
` 0.0 0.0 Infinity -Infinity NaN `