954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

square root of number repeated in loop

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

umair jameel
Newbie Poster
6 posts since Nov 2011
Reputation Points: 10
Solved Threads: 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
}

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

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.

dmanw100
Posting Whiz in Training
242 posts since Apr 2008
Reputation Points: 104
Solved Threads: 27
 

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

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: