Results 1 to 3 of 3
  1. #1
    ihitimdogg is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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 [cod&#101;] above your pasted code and the tag [/cod&#101;] below your pasted code like so:

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

  3. #3
    ihitimdogg is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Problem with bytes and characters
    By PrinceSendai in forum New To Java
    Replies: 1
    Last Post: 09-23-2010, 06:18 AM
  2. Repeating
    By AbdulAziz Bader in forum New To Java
    Replies: 3
    Last Post: 05-05-2010, 11:35 PM
  3. Problem with writing unicode characters in a file
    By ze snow in forum New To Java
    Replies: 1
    Last Post: 02-23-2010, 10:47 PM
  4. Replies: 2
    Last Post: 02-15-2010, 06:49 AM
  5. Replies: 1
    Last Post: 12-30-2008, 04:39 PM

Posting Permissions

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