1,105,625 Community Members

square root of number repeated in loop

Member Avatar
umair jameel
Newbie Poster
7 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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........

Member Avatar
stultuske
Posting Expert
5,326 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
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
}

Member Avatar
dmanw100
Posting Whiz in Training
269 posts since Apr 2008
Reputation Points: 36 [?]
Q&As Helped to Solve: 32 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
stultuske
Posting Expert
5,326 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: