Results 1 to 6 of 6
  1. #1
    smokey888 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default output characters equal to an intiger value?

    basicaly i have a random number gen and i want to output a line of asterix (*) that is equal to the random number e.g if the random number equals 4 i want to output **** if it euqals 15 i want to output ***************


    any help would be apreciated :)

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    build your string of asterix inside a loop.

    loop start
    string += "*";
    loop end

  3. #3
    smokey888 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    dont really understand what you mean in new to java :(

  4. #4
    smokey888 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    This is my programe so far i hope u can understand what im trying to do now

    Java Code:
    /* Thomas Roberts
    horse simulation game.
    */
    import java.util.*;
    public class horse{
    	public static void main(String args[]){
    	/* declare variables */
    	String name ="";
    	String hname1 ="";
    	String hname2 ="";
    	String hname3 ="";
    	String hname4 ="";
    	String as = "";
    	int win = 0;
    	int horse1 =0;
    	int horse2 =0;
    	int horse3 =0;
    	int horse4 =0;
    	int loop = 0;
    	int rndloop = 0;
    	Random gen = new Random();
    	Scanner scr = new Scanner(System.in);
    		
    			horse1 = gen.nextInt(15)+1;
    			horse2 = gen.nextInt(15)+1;
    			horse3 = gen.nextInt(15)+1;
    			horse4 = gen.nextInt(15)+1;	
    	
    	/* send instructions to the screen*/
    		System.out.println("You must first enter your name and then enter the names of the 4 horses in the race.");
    		System.out.println("You must then pick which number horse you want to bet on.");
    		System.out.println("To start the race press 1 and wait for results.") ;
    		System.out.println("This will display the distance traveled in a line of *");
    		
    			System.out.println("Enter your name");
    			name = scr.next();
    			
    				System.out.println("enter the name for horse1");
    				hname1 = scr.next();
    					
    					System.out.println("enter the name for horse2");
    					hname2 = scr.next();
    					
    						System.out.println("enter the name for horse3");
    						hname3 = scr.next();
    					
    							System.out.println("enter the name for horse4");
    							hname4 = scr.next();
    							
    								System.out.println("enter the number of the horse you want to bet on");
    								win = scr.nextInt;
    								
    								System.out.println("press 1 to start the race");
    								loop = scr.nextInt();
    								
    						while(loop == 1){

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by smokey888 View Post
    dont really understand what you mean in new to java :(

    for example this or this

    in the code above i don't understand what you're trying to do inside while. please tell ...
    Last edited by j2me64; 12-17-2010 at 09:48 AM.

  6. #6
    smokey888 is offline Member
    Join Date
    Dec 2010
    Posts
    4
    Rep Power
    0

    Default

    u press 1 to start the race i then want it to output the same number of asterix for each horse as the random number is. untill it reaches 50 and then that horse will be the winner

Similar Threads

  1. <logic:equal> tag
    By satyaprsp in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-18-2010, 07:52 AM
  2. help with not equal to operator !=
    By manowar689 in forum New To Java
    Replies: 9
    Last Post: 06-15-2010, 12:10 AM
  3. How to encode a fileHandler to output french characters ?
    By l.najm@acteos.com in forum Advanced Java
    Replies: 4
    Last Post: 04-22-2010, 09:21 AM
  4. equal() method
    By need_helpp in forum New To Java
    Replies: 3
    Last Post: 03-09-2010, 05:57 PM
  5. checking if there are equal numbers
    By nalinda in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 02:13 AM

Posting Permissions

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