This post contains a total of 8+ Hand-Picked Java Cube Root Finder Program Examples with Source Code. All these Cube root programs are made using Java Programming language.
You can use the source code of these examples with credits to the original owner.
Related Posts
Java Cube Root Finder Programs
1. By Bhattu Khushboo
Made by Bhattu Khushboo. Simple Java program to find cube root of a input number. Source
10 Cube root of 10.0 = 2.154434690031884
import java.util.*;
public class Program
{
public static void main(String[] args) {
double Number = new Scanner(System.in) . nextDouble();
double divider = 0.3333333333333333333333333333333333;
double rootNum = java.lang.Math.pow(Number,divider);
System.out.println("Cube root of "+ Number + " = " + rootNum);
}
}
2. By Jay
Made by Jay. Program that prints the cube roots of numbers in a given range, you have to enter 1st number then second number with comma in between. Source
You entered: 1,3 Searching in the range: 1,3 The cube root of 1 is: 1.0 The cube root of 2 is: 1.2599 The cube root of 3 is: 1.4422
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanInput = new Scanner(System.in);
String input = scanInput.nextLine();
String pattern = "([\\d][,][\\d])";
String pattern2 = "([^,\\d])";
Pattern r = Pattern.compile(pattern);
Pattern r2 = Pattern.compile(pattern2);
Matcher m = r.matcher(input);
Matcher m2 = r2.matcher(input);
System.out.println("You entered: " + input);
if(!m.find() || m2.find()){
System.out.println("You need to enter in the format 'number,number' ");
System.exit(0);
}
String[] inputRange = input.split(",");
if(Integer.parseInt(inputRange[0]) < 1 || Integer.parseInt(inputRange[1]) < 1){
System.out.println("You need to enter two numbers, both being greater than or equal to 1");
System.exit(0);
} else if (Integer.parseInt(inputRange[0]) > Integer.parseInt(inputRange[1])){
System.out.println("Your first number needs to be smaller than the second number");
System.exit(0);
}
System.out.println("Searching in the range: " + input);
for(int j=Integer.parseInt(inputRange[0]); j<=Integer.parseInt(inputRange[1]); j++){
int inputNum = j;
double result = 0.0;
cubeRootFind((double)1,(double)10,(double)1,(double)0,(double)inputNum,result);
}
}
public static double cubeRootFind(double low,double high,double step,double counter,double num,double result){
if(counter >= 6.0){
System.out.println("The cube root of " + (int)num + " is: " + Math.round(result*10000d)/10000d);
return result;
}
for(double i=low; i<high; i+=step){
double lowCube = i*i*i;
double highCube = (i+step)*(i+step)*(i+step);
if(num > lowCube && num < highCube){
counter++;
cubeRootFind(i,i+step,step/10,counter,num,(i+i+step)/2);
break;
} else if (num == lowCube){
result = i;
System.out.println("The cube root of " + (int)num + " is: " + result);
return result;
}
}
return result;
}
}
3. By Eren
Made by Eren. Source
Input number of terms : Number is : 1 and cube of 1 is :1 Number is : 2 and cube of 2 is :8 Number is : 3 and cube of 3 is :27 Number is : 4 and cube of 4 is :64 Number is : 5 and cube of 5 is :125
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
int i,n;
System.out.print("Input number of terms : ");
Scanner in = new Scanner (System.in);
n = in. nextInt ();
for (i=1;i<=n; i++)
System.out.println( "Number is : " +i+ " and cube of " +i+ " is :"+(i*i*i));
}
}
4. By Ashish patjoshi
Made by Ashish patjoshi. Basic java cube root finder program. Source
Enter a number 7 Cube root of the number=1.9129311827723892
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
double a=sc.nextDouble();
double b=Math.cbrt(a);
System.out.println ("Cube root of the number="+b);
}
}
5. By Robert Spanjaard
Made by Robert Spanjaard. Source
9 The cube root of 9 is 2.0800
import java.util.Scanner;
public class CubeRoot
{
public static void main(String[] args)
{
double precision = 0.0001; // requested precision
double increment = 1;
double cubeRoot = 0;
double input = new Scanner(System.in).nextDouble();
while (increment >= precision)
{
cubeRoot += increment;
if (cubeRoot*cubeRoot*cubeRoot > input)
{
cubeRoot -= increment;
increment = increment / 10;
}
}
System.out.printf("The cube root of %.0f is %.4f\n", input, cubeRoot);
}
}
6. By Michel PaeΓens
Made by Michel PaeΓens. Source
Input: 14 Output: 2.41014226417523
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
int num = new Scanner(System.in).nextInt();
double cbrt = Math.cbrt(num);
System.out.println("Input: " + num + " Output: " + cbrt);
}
}
7. By Enma FF
Made by Enma FF. Source
2.5712999999999533
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
double ent;
ent=s.nextDouble();
System.out.println(Mate.raizcubo(ent));
}
}
class Mate{
static double raizprueba(double r){
return r*r*r;
}
public static double raizcubo(double n){
double dat=0;
for (double i = 0; i*i*i<=n; i++) {
if((i*i*i)==n){
dat=i;
break;
}
dat=i;
}
//presicion
double nu=0;
while(n-raizprueba(dat+nu)>=0.0001){
nu+=0.0001;
}
return dat+nu;
}
}
8. By Nguyen Van Thai
Made by Nguyen Van Thai. Very Basic Java Cube root program. Source
enter your number 4 cube root : 1.5874010519681996
import java.util.Scanner;
public class main {
public static void main(String[] args) {
System.out.println(" enter your number");
float x = new Scanner(System.in).nextFloat();
System.out.println("cube root : " + Math.cbrt(x));
}
}
9. By Saroj Patel
Made by Saroj Patel. Java Program to find cube root and square root of a number. Source
You Entered :11.0 Square root is : 3.3166247994818185 Cube root is : 2.223980099633439
import java.util.Scanner;
public class RootDemo {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
double num = sc.nextDouble();
System.out.println("You Entered :"+num);
sc.close();
sqrt(num);
cbrt(num);
}
public static void sqrt(double num) {
double i=1,precision=0.0000001;
for(i=1;(i*i)<=num;i++);
for(--i;(i*i)<num;i+=precision);
System.out.println("Square root is : "+i);
}
public static void cbrt(double num) {
double i=1,precision=0.0000001;
for(i = 1;(i*i*i)<=num; ++i);
for(--i;(i*i*i)<num;i+=precision);
System.out.println("Cube root is : "+i);
}
}