Here's some comments added to the code to explain what's going on. :-)

import java.util.*;

public class RandomNumberPrinter
{
    // Constants.
    public static final int ARRAY_SIZE = 50;
    public static final int MAX_NUMBER = 999;

    public static void main( String[] args )
    {
        // Create an empty set to store the unique random numbers.
        LinkedHashSet<Integer> numberSet = new LinkedHashSet<Integer>();

        // Create a random number generator.
        Random random = new Random();

        // While the set is smaller than the required size (50)...
        while( numberSet.size() < ARRAY_SIZE )
        {
            // ...add a random number between 0 and the maximum number (999).
            // Note: if a value is added that is already in the set, it will be
            //       overwritten, so the set will stay the same size.
            numberSet.add( random.nextInt( MAX_NUMBER + 1 ) );
        }

        // Convert the set into an array.
        Integer[] numbers = numberSet.toArray( new Integer[ 0 ] );

        // Print out the numbers in a 10 x 5 grid.
        for( int row = 0; row < 5; ++row )
        {
            for( int col = 0; col < 10; ++col )
            {
                int index = ( row * 10 ) + col;
                System.out.printf( "%03d ", numbers[ index ] );
            }
            System.out.println();
        }
    }
}

LinkedHashSet<T> - This class holds a set of unique values of type 'T'.

whats the 'T' stand for? sorry for being a pain

hi
we can use Random class to get random numbers and also between 1 and 999 as you said...

LinkedHashSet<T> - This class holds a set of unique values of type 'T'.

whats the 'T' stand for? sorry for being a pain

Take a look here.

thanx guys : )

No problem, please mark the thread as solved.

thanx guys : )

No problem mate, glad to help! :-D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.