- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java cbrt() method with Examples
The java.lang.Math.cbrt(double a) returns the cube root of a double value. For positive finite x, cbrt(-x) == -cbrt(x); that is, the cube root of a negative value is the negative of the cube root of that value's magnitude. Special cases −
If the argument is NaN, then the result is NaN.
If the argument is infinite, then the result is an infinity with the same sign as the argument.
If the argument is zero, then the result is a zero with the same sign as the argument.
Example
Following is an example to implement the cbrt() method in Java −
import java.lang.*; public class Example { public static void main(String[] args) { // get two double numbers double x = 125; double y = 10; // print the cube roots of three numbers System.out.println("Math.cbrt(" + x + ")=" + Math.cbrt(x)); System.out.println("Math.cbrt(" + y + ")=" + Math.cbrt(y)); System.out.println("Math.cbrt(-27)=" + Math.cbrt(-27)); } }
Output
Math.cbrt(125.0)=5.0 Math.cbrt(10.0)=2.154434690031884 Math.cbrt(-27)=-3.0
Example
Let us see another example −
import java.lang.*; public class Example { public static void main(String[] args) { // get two double numbers double x = 0.0; double y = -343.0; // print the cube roots of three numbers System.out.println("Math.cbrt(" + x + ")=" + Math.cbrt(x)); System.out.println("Math.cbrt(" + y + ")=" + Math.cbrt(y)); } }
Output
Math.cbrt(0.0)=0.0 Math.cbrt(-343.0)=-7.0
- Related Articles
- Java signum() method with Examples
- Java lang.Long.toBinaryString() method with Examples
- Java ceil() method with Examples
- Java sqrt() method with Examples
- Java floor() method with Examples
- Java toDegrees() method with Examples
- Java Signature getAlgorithm() method with Examples
- Java Signature getInstance() method with Examples
- Java Signature getProvider() method with Examples
- Java Signature initSign() method with Examples
- Java Signature toString() method with Examples
- Java lang Integer.toHexString() Method with Examples
- Java lang Long.toOctalString() Method with Examples
- Java streams counting() method with examples
- MatchResult start() method in Java with examples.

Advertisements