Results 1 to 6 of 6

Thread: Random number

  1. #1
    Hawks is offline Member
    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0

    Default Random number

    Thanks for all the help!
    Last edited by Hawks; 04-30-2013 at 04:49 AM.

  2. #2
    Join Date
    Apr 2013
    Posts
    41
    Rep Power
    0

    Default Re: Random number

    i figure your new so atleast look this over...

    Java Code:
    int total = 0, count = 0, r;
    		Random randomGenerator = new Random();
    		
    		do{
    			r = randomGenerator.nextInt(11)+1;
    			total = total + r;
    			count++;
    		}
    		while(total <= 21);
    		System.out.println(count);
    	}

  3. #3
    Hawks is offline Member
    Join Date
    Feb 2013
    Posts
    13
    Rep Power
    0

    Default Re: Random number

    Thank you so much, you are amazing!

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Random number

    Don't edit your posts like that. Now this post is of no value to anyone else.
    Get in the habit of using standard Java naming conventions!

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: Random number

    Here's the original content:

    -

    How would I generate random numbers between 1-11 and when they total up to 21 or greater the systems tells me how many generated
    numbers there were that added up to 21?

    I have this so far, I think I am suppose to use RandomNumber command.

    for (int i = 1; i < 11; i++)
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,912
    Rep Power
    5

    Default Re: Random number

    OP aksed, "How would I generate random numbers between 1-11 and when they total up to 21 or greater the systems tells me how many generated
    numbers there were that added up to 21?"


    Hmm, what is the count when the first eight generated numbers are 4,8,3,2,4,9,10,1?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Random number
    By _Chip in forum New To Java
    Replies: 4
    Last Post: 11-03-2012, 08:06 PM
  2. Random number not gen. number 0???
    By Mr U in forum New To Java
    Replies: 2
    Last Post: 10-17-2012, 03:18 AM
  3. Random number generator
    By adjit in forum New To Java
    Replies: 9
    Last Post: 03-05-2012, 05:09 PM
  4. Random number help
    By jgonzalez14 in forum New To Java
    Replies: 5
    Last Post: 09-16-2008, 10:13 AM
  5. Random number
    By jithan in forum Advanced Java
    Replies: 1
    Last Post: 06-13-2008, 02:42 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
  •