java.lang.Math cbrt(double a)

Description :

This java tutorial shows how to use the cbrt(double a) method of Math class under java.lang package. This method returns the cube root of the method argument.

Method Syntax :

public static double cbrt(double a)

Parameter Input :

DataType Parameter Description
double a the value which we want to determine cube root.

Method Returns :

The cbrt(double a) method simply returns the positive cube root of a. Consider the following cases:

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

Compatibility Version :

Requires Java 1.5 and up

Exception :

N/A

Java Code Example :

This java example source code demonstrates the use of cbrt(double a) method of Math class. Basically we just get the cube root of a value from the user input.

package com.javatutorialhq.java.examples;

import static java.lang.System.*;

import java.util.Scanner;

/*
 * This example source code demonstrates the use of 
 * cbrt(double a) method of Math class
 * Get the cube root value of the user input
 */

public class MathCubeRoot {

	public static void main(String[] args) {
		// ask for user input
		out.print("Enter a value:");
		Scanner scan = new Scanner(System.in);
		// use scanner to get user console input
		double value = scan.nextDouble();		
		// get the cube root of a value
		double sqrtValue = Math.cbrt(value);
		out.println("cube root of "+value+" = "+sqrtValue);		
		// close the scanner object to avoid memory leak
		scan.close();

	}

}

Sample Output :

Running the cbrt(double a) method example source code of Math class will give you the following output

Enter a value:8
cube root of 8.0 = 2.0

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :