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
doublevalue. - The cube root of a number
xis the numberysuch thaty³ = 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
š„ Parameters
a: adoublevalue 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
NaNif the input isNaN.
Java Tutorials
Java Tutorial on this website:
