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.

Results 1 to 4 of 4

Thread: How to generate multiple random numbers?

  1. #1
    Member
    Join Date
    Oct 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to generate multiple random numbers?

    Create a Randoms application that generates 16 random numbers between 1 and 100, inclusive and displays them in rows of 4.

    So here's what I have so far:

    import java.util.Random;

    class randoms {
    public static void main(String args[]){
    Random number = new Random();
    int num = 0;
    int total = 16;

    while(num < 11){
    num = 1+number.nextInt(100);
    System.out.println(num);



    }

    }
    }

    Except that this code can only generate one random number when you run it, how do you generate multiple random numbers?


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: How to generate multiple random numbers?

    Generate 16 numbers
    Between 1 and 100
    Print in row s of 4

    WTF is your loop condition < 11?
    Improving the world one idiot at a time!

  3. #3
    Member
    Join Date
    Oct 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to generate multiple random numbers?

    Quote Originally Posted by Junky View Post
    Generate 16 numbers
    Between 1 and 100
    Print in row s of 4

    WTF is your loop condition < 11?
    so how do you fix it?

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: How to generate multiple random numbers?

    Use your brain. Think about exactly what you need to do. First thing is how would you generate 100 numbers?
    Improving the world one idiot at a time!

Similar Threads

  1. How to generate random numbers in Java?
    By jls24 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 7th, 2013, 01:31 AM
  2. Generate random numbers between 1 and 52 by passing a seed to Random.
    By Shareefuddin in forum Object Oriented Programming
    Replies: 2
    Last Post: April 22nd, 2013, 09:48 AM
  3. Replies: 1
    Last Post: February 15th, 2013, 08:03 PM
  4. Generation of random number using random class
    By JavaPF in forum Java SE API Tutorials
    Replies: 1
    Last Post: December 7th, 2011, 05:46 PM
  5. Generation of random number using random class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 16th, 2009, 06:10 AM