DEV Community

Its Aomi
Its Aomi

Posted on

Basic Java Cube Root Program

Here is a very basic cube root finder program made using java.

Get more Code examples here.

So, this is a very basic program, it just takes a input number and prints out its cube root using Math cbrt().

First it uses the Java Util Scanner Class to get the user input, then it converts the input to cube root using math.cbrt and prints the output.

import java.util.Scanner;
public class Program
{
    public static void main(String[] args) {
        // Creates Integer num
        int num = new Scanner(System.in).nextInt();
        // Converts the Int to Cube Root using Math.cbrt
        double cbrt = Math.cbrt(num);
        // Prints the Output
        System.out.println("Input Number: " + num + " Output: " + cbrt);
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

Input Number: 10 
Output: 2.154434690031884
Enter fullscreen mode Exit fullscreen mode

Top comments (0)