Java Math cbrt()

Learn via video course
FREE
View all courses
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Topics Covered

Overview

Java cbrt() method defined in the Math class calculates the cube root of a double value.

  • Java cbrt() method returns NaN if the input argument is NaN.
  • Java cbrt() method returns Infinity if the argument is infinite with the same sign as the argument.
  • Java cbrt() method returns zero if the argument is zero with the same sign as the argument.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax of Math cbrt() in Java

The syntax of cbrt() method is given below.

The Java cbrt() method is a static method of Math class.

Parameters of Math cbrt() in Java

The cbrt() method takes only single parameter.

  • num: A numeric value of double type whose cube root is to be computed.

Return Value of Math cbrt() in Java

  • The cbrt() method returns NaN if passed value is NaN.
  • The cbrt() method returns zero if number passed is zero with the same sign.
  • If the argument is Infinite then cbrt() will return Infinity with same sign.
  • Return type is double

Note: If the number passed as argument is a negative number then cbrt() method will return a negative number. cbrt(-num) = -cbrt(num).

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Exceptions of Math cbrt() in Java

cbrt() method does NOT throw any exception.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example

In this sample code, we are going to see how to use cbrt() method in java.

Output

Code Explanation

  • In the above code, we have used cbrt() method to find the cube root of 27 and -125.
  • As the cube root of 27 is 3 so it will return 3.0.
  • And as we discussed above, cube root of a negative number will be negative so cbrt() will return -5.0 as a cube root of -125.

What is Math cbrt() in Java?

The cube root of a numeric value can be computed using the cbrt() method in Java.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

More Examples

Example 1

Finding Cube root of Positive Infinity

Output:

Explanation:

  • As we discussed above if argument is infinite then it will return Infinity with same sign as argument.

Example 2

In this example we are going to find cube root of zero with positive and negative signs.

Output:

Explanation:

  • As discussed above, if the argument is zero, the return value of cbrt() method is also zero with the same sign.

Example 3

In this example we are going see the return value of Java cbrt() method when the argument is NaN.

Output:

Explanation:

  • As discussed above, if the argument is NaN, the return value of Java cbrt() method is also NaN.

Conclusion

  • Math.cbrt() method is used to find the cube root of given number.
  • Java cbrt() method returns NaN if the input argument is NaN.
  • Java cbrt() method returns Infinity if the argument is infinite with the same sign as the argument.
  • Java cbrt() method returns zero if the argument is zero with the same sign as the argument.