Java .cbrt()

ruby6867892668's avatar
Published Nov 7, 2022Updated Nov 9, 2022
Contribute to Docs

The Math.cbrt() method returns the cube root of a double value.

  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

Syntax

Math.cbrt(double num)

The .cbrt() method will return the cube root of num. The value of num can be any real number. Edge cases for this method include:

  • If the argument is NaN, the return value will be NaN.
  • If the argument is ±infinity, the return value will be ±infinity.

Example

Here is an example using the Math.cbrt() method:

public class Main {
public static void main(String[] args) {
double a = 27.0;
System.out.println("Math.cbrt(" + a + ") returns: " + Math.cbrt(a));
double b = -8.0;
System.out.println("Math.cbrt(" + b + ") returns: " + Math.cbrt(b));
}
}

This will result in the following output:

Math.cbrt(27.0) returns: 3.0
Math.cbrt(-8.0) returns: -2.0

All contributors

Contribute to Docs

Learn Java on Codecademy

  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours