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.
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 27System.out.println( "Cube Root of 27 is: "+ Math.cbrt(27) );// calculate the cube root of 8System.out.println( "Cube Root of 8 is: "+ Math.cbrt(8) );// calculate the cube root of 64System.out.println( "Cube Root of 64 is: "+ Math.cbrt(64) );}}
Code explanation
- Line 4: We calculate the cube root of
27and display the results usingSystem.out.println. - Line 6: We calculate the cube root of
8and display the results usingSystem.out.println. - Line 8: We calculate the cube root of
64and display the results usingSystem.out.println.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved