What is the Math.cbrt() method in Java?

Overview

In mathematics, the cube root of a number refers to another number, which, multiplied thrice by itself, produces that number.

Example

The cube root of the number 27 is 3. We can see how in the example below.

%0 node_1645690772799 3 node_1645690820325 * node_1 3 node_2 * node_3 3 node_1645690816621 = node_1645690772029 27
Cube root example

Cube root in Java

We use the Math.cbrt() method in Java to find the cube root of a given number.

Syntax

The implementation header of Math.cbrt() function in Java is given below:

public static double cbrt(double x)

To call this function, we use the following syntax:

double cuberoot = Math.cbrt(27)

Parameters

The cbrt() function takes a double value, whose cube root is to be determined, as a parameter. It also returns the cube root as a double value.

Code example

The example below demonstrates the use of the Math.cbrt function to find the cube roots of several numbers.

class CubeRoot{
public static void main( String args[] ) {
// calculate the cube root of 27
System.out.println( "Cube Root of 27 is: "+ Math.cbrt(27) );
// calculate the cube root of 8
System.out.println( "Cube Root of 8 is: "+ Math.cbrt(8) );
// calculate the cube root of 64
System.out.println( "Cube Root of 64 is: "+ Math.cbrt(64) );
}
}

Code explanation

  • Line 4: We calculate the cube root of 27 and display the results using System.out.println.
  • Line 6: We calculate the cube root of 8 and display the results using System.out.println.
  • Line 8: We calculate the cube root of 64 and display the results using System.out.println.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved