Java Math cbrt() Method

java math cbrt() method

Java Math Class

Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), abs() etc.
The java.lang.Math class contains various methods for performing basic numeric operations

Here, in the page we will discuss about the math cbrt() Method in java.

Java Math cbrt() Method :

The cube root of a double value is returned by the Java.lang.Math.cbrt() method.

Special Points :

  • If the argument is NaN, the outcome will also be NaN.
  • If the argument is infinite, the answer is also infinite and has the same sign.
  • If the argument is zero, the result will also be zero with the same sign.

Syntax  :

public static double cbrt(double a)

Example 1 :  

Run
import java.lang.Math;
class Main{

	// driver code
	public static void main(String args[])
	{
		double a = 145.0;
		double b = 5.0 / 0;
		double c = -(2.0 / 0);
		double d = 0.0;
		double e = -0.0;

		System.out.println(Math.cbrt(a));

		// Input Positive Infinity
		// Output Positive Infinity
		System.out.println(Math.cbrt(b));

		// Input Negative Infinity
		// Output Negative Infinity
		System.out.println(Math.cbrt(c));

		// Input Positive Zero
		// Output Positive Zero
		System.out.println(Math.cbrt(d));

		// Input Negative Zero
		// Output Negative Zero
		System.out.println(Math.cbrt(e));
	}
}

Output :

5.2535878724929015
Infinity 
-Infinity
0.0      
-0.0     

Example 2 for Infinite Number :  

Run
import java.lang.Math;

class Main{

	public static void main(String args[])
	{
		
		double b = 20.0 / 0;
		double c = -(10.0 / 0);
	
		// Input Positive Infinity
		// Output Positive Infinity
		System.out.println(Math.cbrt(b));

		// Input Negative Infinity
		// Output Negative Infinity
		System.out.println(Math.cbrt(c));
	}
}

Output :

Infinity 
-Infinity

Example 3 for Zero Input Number :  

Run

import java.lang.Math;

class Main{

	public static void main(String args[])
	{
	
		double d = 0.0;
		double e = -0.0;

		// Input Positive Zero
		// Output Positive Zero
		System.out.println(Math.cbrt(d));

		// Input Negative Zero
		// Output Negative Zero
		System.out.println(Math.cbrt(e));
	}
}

Output :

0.0
-0.0

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription