# Thread: problem with repeating characters

1. Member
Join Date
Mar 2011
Posts
2
Rep Power
0

## problem with repeating characters

Java Code:
package timsittlerbounceingball;
import java.util.Scanner;

public class Main {

public static void main(String[] args)

{

Scanner keyboard= new Scanner(System.in);
double vel, newvel, bounce, time, height;
bounce=0;
time=1;
System.out.println("Enter the inital velocity of the ball");
vel=keyboard.nextDouble();
height=vel;
System.out.println("Time:0 Height:0");
System.out.println("Time:1 Height:"+ vel);

while(bounce<6)
{
vel=vel-32; // code for velocity equation and resulting height
newvel=vel;
height=height+newvel;

time++;
if (height<0) //simulates the bounce
{
height=height*-.5;
vel=vel*-.5;
System.out.println("Time:"+time+" Height:"+height);
bounce++;
}
else // during time in the air
System.out.println("Time:"+time+" Height:"+height);

}

}
}

this is a simple loop for a bounceing ball. What i need to do is to get a certain number of "*" to appear next to my height number. The number of "*" is dependent to height that is generated. For the life of me i can not figure this out. in other words i need a way to multiply "*" by the height. Any help would be great. Just need to be pointed in the right direction. Thanks
(p.s. very very new to the whole progamimg thing)
Last edited by Fubarable; 03-19-2011 at 10:43 PM. Reason: Moderator Edit: code tags added

2. Welcome to the forum. I suggest that you calculate your number, then use a loop to write out the "*" character based on this number. Since you'll know before the loop how many times you'll want the loop to occur, a for loop would work best. Since you want to print the "*" without carriage returns, you'll want to use System.out.print(...) inside the loop, and System.out.println() just after the for loop.

To do this yourself, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

Java Code:
[cod&#101;]
// notice how the top and bottom tags are different
[/cod&#101;]
Best of luck, and again, welcome!

3. Member
Join Date
Mar 2011
Posts
2
Rep Power
0
got it thanks so much

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•