Results 1 to 3 of 3
- 03-19-2011, 08:37 PM #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 09:43 PM. Reason: Moderator Edit: code tags added
-
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.
I edited your code and added code tags which should help make your posted code retain its formatting and be more readable.
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 [code] above your pasted code and the tag [/code] below your pasted code like so:
Best of luck, and again, welcome!Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
- 03-19-2011, 10:10 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Problem with bytes and characters
By PrinceSendai in forum New To JavaReplies: 1Last Post: 09-23-2010, 06:18 AM -
Repeating
By AbdulAziz Bader in forum New To JavaReplies: 3Last Post: 05-05-2010, 11:35 PM -
Problem with writing unicode characters in a file
By ze snow in forum New To JavaReplies: 1Last Post: 02-23-2010, 10:47 PM -
Problem displaying UNICODE characters on a JLabel
By lumpy in forum New To JavaReplies: 2Last Post: 02-15-2010, 06:49 AM -
Problem while inserting UTF-8 characters in MS-SQL Server 2000 Database
By sagarsway in forum JDBCReplies: 1Last Post: 12-30-2008, 04:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks