dimanche 21 juin 2015

How to print a 2D array with random numbers

I am trying to write a program that prints a 2d array with random numbers ranging from 100-10000 and prints out the max number in the array,average,and min. The program will ask the user for the number of rows and column and print random numbers in that array.

Here is my code:

Random rand = new Random();

int randomnumber = rand.nextInt(9901) + 100;

Scanner console = new Scanner(System.in);

System.out.println("Enter row");
int n = console.nextInt();

System.out.println("Enter column");
int y = console.nextInt();

int[][] array = new int[n][y];
array[n][y] = randomnumber;

int k;
for (int i = 0; i <= array.length; i++) {
    for (k = 0; k <= array[i].length; k++) {
        System.out.print(array[i][k]);
    }
}




Aucun commentaire:

Enregistrer un commentaire