Java

Java cbrt() Method

Java cbrt() Method

In Java, the cbrt() method is used to calculate the cube root of a number. This method is part of the java.lang.Math class.

Method Signature

public static double cbrt(double a)

Package

This method is part of the java.lang.Math class.

Description

  • Returns the cube root of a specified double value.
  • The cube root of a number x is the number y such that y³ = x.

Syntax Example

Sample Java program that shows the use of cbrt() method:

public class CubeRootExample {
    public static void main(String[] args) {
        double number = 27.0;
        double result = Math.cbrt(number);
        System.out.println("Cube root of " + number + " is: " + result);
    }
}

 

Program Output

Cube root of 27.0 is: 3.0

Java cbrt method

Parameters

  • a: a double value whose cube root is to be determined.

Returns

  • The cube root of the argument.

More Examples

System.out.println(Math.cbrt(8));      // 2.0
System.out.println(Math.cbrt(-125));   // -5.0
System.out.println(Math.cbrt(0));      // 0.0

Notes

  • Works with negative numbers (returns a negative result).
  • Returns NaN if the input is NaN.

 

Java Tutorials

Java Tutorial on this website: