1.11M Members

square root of number repeated in loop

 
1
 

How print this series in while loop
square root 1 2 4 8 16 32 64 128..........
and
cube root 2 8 24 72........

 
0
 

by writing a loop and adding a print statement in it:

step 1:
highBorder = readInHighBorder
step 2:
counter = 1
step 3:
while ( counter < highBorder ){
squareRoot = calculateTheSquareRootOfCounter
printSquareRoot
cubeRoot = calculateTheCubeRootOfCounter
printCubeRoot
add1ToCounter
}

 
0
 

I'm assuming you're doing this to learn Java, so this should get you started:

int counter = 0; // Declare your variables
int value = 1;
int max = 10; // You can define ("hard code") this, or read it in
while(counter < max) {
	System.out.println(value + " "); // This handles printing
	value = value * 2;
	counter++; // This will track how many numbers have already been printed
}

You can use that as a basis for figuring out the cubic part. The mechanics are essentially the same.

 
0
 

I'm assuming you're doing this to learn Java, so this should get you started:

int counter = 0; // Declare your variables
int value = 1;
int max = 10; // You can define ("hard code") this, or read it in
while(counter < max) {
	System.out.println(value + " "); // This handles printing
	value = value * 2;
	counter++; // This will track how many numbers have already been printed
}

You can use that as a basis for figuring out the cubic part. The mechanics are essentially the same.

two remarks:
1 -> don't spoon feed code.
2 -> if you feel the need to spoon feed code anyway, make sure your code makes sense. I doubt you'll find the square root of 25 by value= value*2

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: