Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31

Thread: Counting and Math.random

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Counting and Math.random

    Ok, that looks about right.
    For testing to see what is in the array use the Arrays class's toString() method:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayNameHere));
    If you don't understand my answer, don't ignore it, ask a question.

  2. The Following User Says Thank You to Norm For This Useful Post:

    Elyril (March 9th, 2014)

  3. #27
    Member
    Join Date
    Feb 2014
    Posts
    58
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default Re: Counting and Math.random

    System.out.println("\n Random: " + java.util.Arrays.toString(counts));
    and the result being
    1 8 7 7 3 1 5 4 8 3 8 2 9 6 5 4 0 3 7 1 
     Random: [1, 3, 1, 3, 2, 2, 1, 3, 3, 1]
    Is the print out the amount of each specific number? and if so, is there a way so I can specify which amount is for which number?

  4. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Counting and Math.random

    specify which amount is for which number?
    Write a loop like you had before that prints the index value and the contents of the array at that index.

    Is the print out the amount of each specific number?
    That is easily verified by looking at the numbers that were printed on the line above the line showing the contents of the array.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Elyril (March 9th, 2014)

  6. #29
    Member
    Join Date
    Feb 2014
    Posts
    58
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default Re: Counting and Math.random

    Thank you so much! I feel like my head was going to explode...

  7. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Counting and Math.random

    Hopefully arrays will be easier next time.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #31
    Member
    Join Date
    Feb 2014
    Posts
    58
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default Re: Counting and Math.random

    Yes, I hope so too. I should also take it slow and think. Thank you again

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Java Math.random() and loop
    By maple1100 in forum What's Wrong With My Code?
    Replies: 23
    Last Post: December 28th, 2012, 12:23 PM
  2. Math.random() with no duplictaes
    By jaydac12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 6th, 2012, 07:42 AM
  3. Problems with Math.Random() in a for loop
    By csharp100 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 27th, 2012, 06:18 PM
  4. Need help understanding math.random method.
    By slashdash in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 23rd, 2012, 05:50 PM
  5. Math.Random()
    By xionyus in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 26th, 2011, 10:22 PM