Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
math
cuberoot
communitycreator

# What is Math.cbrt in Java? Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The cbrt method is used to find the cube root of a double value. cbrt is a static method present in the Math class.

### Syntax

Math.cbrt(double num);


The cbrt method returns the cube root of the argument. For example, the cube root of 27 is 3. The return type of the cbrt method is double. If the argument is negative, then the cbrt(-num) will be computed internally by -cbrt(num).

For NaN , POSITIVE_INFINITY , NEGATTIVE_INFINITY, +0, -0 the return value is the same as the argument.

### Example

class CbrtExample {
public static void main( String args[] ) {
double num = 27.0;
System.out.println( "cbrt(27.0) : " + Math.cbrt(num) );

num = -125.0;
System.out.println( "cbrt(-125.0) : " + Math.cbrt(num) );

num = 1.0; // infinity
System.out.println( "cbrt(1.0) : " + Math.cbrt(num) );

num = -0.0;
System.out.println( "cbrt(-0.0) : " + Math.cbrt(num) );

num = 10; // infinity
System.out.println( "cbrt(10) : " + Math.cbrt(num) );

}
}

In the code above, we have used the Math.cbrt function to find the cube root of the numbers.

• For the number 27.0, the cube root value will be 3.0. 3*3*3 will produce 27.

• For the number -125.0, the cube root value will be -5.0. 5 * 5 * 5 will produce 125. The argument is negative so the - sign is added to the 5 and -5.0 will be returned.

• For the number 1.0, the cube root value will be 1.0.

• For the number -0.0, the cube root value will be -0.0.

• For the number 10, the cube root value will be 2.154434690031884.

RELATED TAGS

java
math
cuberoot
communitycreator

CONTRIBUTOR Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 