import java.util.*;

// fill in an array with random integers

public class RandomElements {

    public static void main (String [] args)  {
	// create the array
	int [] a = new int[9];
	Random r = new Random();

	// read the elements
	for (int i = 0; i < a.length; ++i) {
	    a[i] = r.nextInt(10);
	}

	// print out the elements to check:
	for (int i = 0; i < a.length; ++i) {
	    System.out.println("a[" + i +"] = " + a[i]);
	}	
    }
}

This is an example from CSci 1211 course.