Java.lang Package Classes

Java Math - cbrt() Method



The java.lang.Math.cbrt() method returns the cube root of the given number. In special cases it returns the following:

  • 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.

Syntax

public static double cbrt(double a)

Parameters

a Specify a number.

Return Value

Returns the cube root of the specified number.

Exception

NA.

Example:

In the example below, cbrt() method is used to find out the cube root of the given numbers.

import java.lang.*;

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.cbrt(25)); 
  System.out.println(Math.cbrt(30)); 
  System.out.println(Math.cbrt(35.5)); 
  System.out.println(Math.cbrt(-25));     
 }
}

The output of the above code will be:

2.924017738212866
3.1072325059538586
3.2865692257212147
-2.924017738212866

❮ Java.lang - Math

5