To calculate the cube root and the square root of a double
value we can use the Math.cbrt(double a)
and Math.sqrt(double a)
static method call.
package org.kodejava.math;
public class CubeSquareRootExample {
public static void main(String[] args) {
double cube = 125.0d;
double square = 100.0d;
// Get the cube root of double value
double cubeRoot = Math.cbrt(cube);
System.out.println("Cube root of " + cube + " is " + cubeRoot);
// Get the square root of double value
double squareRoot = Math.sqrt(square);
System.out.println("Square root of " + square + " is " + squareRoot);
}
}
This snippet will print the following output:
Cube root of 125.0 is 5.0
Square root of 100.0 is 10.0
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024