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.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.