×

Java Math cbrt() Method

The cbrt() method of Math class returns the cube root of a double value.

Syntax:

public static double cbrt(double a)

Parameters:

The parameter ‘a’ represents the value whose cube root is to be determined.

Return Value:

The cbrt () method returns the cube root of the specified value.

  • It returns NaN, if we pass a NaN.
  • It returns infinity with the same sign as the argument, if we pass a positive infinite argument.
  • If we pass zero as an argument, it will return zero with the same sign as the argument.

Example 1:

public class JavaMathCbrtExample1 {
    public static void main(String[] args) {
        double a=8.0;
        //returns the cube root of a double value
        System.out.println("Cube root of "+ a +" = "+Math.cbrt(a));
    }
}

Output:

Cube root of 8.0 = 2.0

Example 2:

public class JavaMathCbrtExample2 {
    public static void main(String[] args) {
        double a=-0.0d/0.0d;
        //returns the cube root of a NaN value
        System.out.println("Cube root of "+ a +" = "+Math.cbrt(a));
    }
}

Output:

Cube root of NaN = NaN

Example 3:

public class JavaMathCbrtExample3 {
    public static void main(String[] args) {
        double a=-0.0;
        //returns a zero with the same sign as the argument ,if the argument is zero.
        System.out.println("Cube root of "+ a +" = "+Math.cbrt(a));
    }
}

Output:

Cube root of -0.0 = -0.0

Example 4:

public class JavaMathCbrtExample4 {
    public static void main(String[] args) {
        double a=-5/0.0;
        //returns infinity with the same sign as the argument ,if the argument is infinity.
        System.out.println("Cube root of "+ a +" = "+Math.cbrt(a));
    }
}

Output:

Cube root of -Infinity = -Infinity

Related Topics

Types of JDBC Drivers

JDBC Drivers: A piece of software known as JDBC Driver permits database communication between Java applications and the server. In order to communicate with our database server, JDBC drivers put into practice...

4 minutes read.

How to add 4 Hours to the Current Date in Java?

In this tutorial, we will learn how to add 4 hours to the local or current date in Java language. We will begin our topic with basic concepts and would...

2 minutes read.

DatabaseMetaData in Java

The Data about another data is called Meta data. The DatabaseMetaData interface has the meta data of the database present in the system. It consists of database product name, total...

2 minutes read.

Can Abstract Classes have Static Methods in Java

Abstract Class An abstract class in Java is one that explicitly uses the keyword "abstract" in its declaration. There are options for both non-abstract and abstract techniques (method with the body)....

4 minutes read.

How to Convert String to long in Java

How to Convert String to long in java It is used when you want to perform the mathematical operation on the String which contains long number then the conversion from String...

4 minutes read.

Types of Statements in Java

In natural languages, statements and sentences are roughly equivalent. In general, statements are similar to valid English sentences. We will talk about a statement in Java and the different kinds...

11 minutes read.

Time Class Operation in Java

The Java SQL package includes the time class. This class is merely a lightweight wrapper for java. util. THANKS TO THE recognize BC API can recognize this as a SQL...

3 minutes read.

How Many Ways to Create Objects in Java

Introduction Java comes under the category of object-oriented programming languages. Since it is object-oriented, everything in Java is considered an object. Java is a diverse programming language that is designed to...

6 minutes read.

Get year from date in Java

The getYear() method of the Java date class returns a number calculated by deducting 1900 from the year that contains or starts with the instant in time represented by this...

4 minutes read.

Creation of Multi Thread in java

What are threads in Java? We can use threads to facilitate parallel processing. Threads are helpful when you wish to execute several pieces of code concurrently. A thread is a small process...

3 minutes read.

Java Integer reverseByte() method

The reverseByte() method of Java Integer class returns the value obtained by reversing the order of the bytes in the 2’s complement binary representation. Syntax public static int reverseByte (int i) Parameters The parameter...

1 minute read.

Order of Execution of Constructors in Java Inheritance

Constructor in Java There are several distinctions between a method and a function object() in Java. The name of the function object()  is identical to the class name. There is no...

4 minutes read.

Java vs Golang

Java Java is both a programming language and a platform. Java is a high-level, dependable, object-oriented, and secure programming language. Java was developed in 1995 by Sun Microsystems, which is now an...

4 minutes read.

Equidigital in Java

In this section, we will understand what is an equidigital number and how to write Java programs to locate them. It is commonly asked in academic settings and Java coding...

4 minutes read.

Java Boolean logicalXor() Method

The logicalXor() method of Java Boolean class returns the result of implementing logical XOR operation on the specified Boolean operands. Syntax: public static boolean logicalXor (boolean a, boolean b) Parameters: The parameters ‘a’ and...

2 minutes read.

Char and String differences in Java

Characters in Java Character (char) belongs to the characters group, which represents symbols in a character set, such as alphabets and numerals. A Java char has 16 bits in length and has a range...

5 minutes read.

Java Technologies List

Introducing Java technology is not necessary. Everyone across the globe is still in awe of Java's incredible capabilities for developing mobile apps and websites. Of course, you can be persuaded...

8 minutes read.

Timestamp Operation in Java

JDBC escape syntax is supported by Timestamp's formatting and parsing functions. Additionally, it adds support for fractional seconds values for SQL TIMESTAMP.java.util.Date is wrapped in a lightweight wrapper that enables...

3 minutes read.

What is Core Java?

The fundamental Java, which includes the fundamental idea of the Java programming language, is referred to as "Core Java." The definition of "Core" is the core idea of something. Core...

3 minutes read.

How to add 24 Hours to Date in Java?

In this tutorial, we will learn how to add 24 hours to the local or current date in Java language. We will begin our topic with basic concepts and would...

2 minutes read.