In mathematics, the cube root of a number refers to another number, which, multiplied thrice by itself, produces that number.
The cube root of the number 27 is 3. We can see how in the example below.
We use the Math.cbrt()
method in Java to find the cube root of a given number.
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)
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.
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) );}}
27
and display the results using System.out.println
.8
and display the results using System.out.println
.64
and display the results using System.out.println
.Free Resources