<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// Generate matrix of random digits
// suggested by Ben Edelman


import java.util.*;

public class array_random {
    
    public static void main(String args[]) {

	// Input rows and cols for array:
	TokenReader in = new TokenReader(System.in);
	System.out.print("Enter # of rows: ");
	int rows = in.readInt();
	System.out.print("Enter # of cols: ");
	int cols = in.readInt();
	System.out.println();

	// Create object for generating random numbers
	Random r = new Random();

	// Array a stores random numbers
	int[][] a = new int[rows][cols];

	// Store random elements
	for(int i=0; i&lt;rows; i++) {
	    for(int j=0; j&lt;cols; j++) {

		// Generate random number with r.nextInt()
		// Divide that number by 10
		// Store the remainder as the element
		// So, a[i][j] will store random digits 0-9
		
		a[i][j] = Math.abs(r.nextInt() % 10);
		System.out.print(a[i][j] + " ");
	    }
	    System.out.println();
	}
	
    } // method main

} // class array_random
</pre></body></html>