Draw of positions of an array

-2

I need to create a function to sort within an array full of 0 with size n x n, four positions to modify the value of only those positions drawn.

    
asked by anonymous 05.04.2018 / 18:45

1 answer

0

Use the java.util.Random class and then something of this genus:

void fillRandomPositions(int[][] arr, int n, int positions) {
    Random rnd = new Random();
    for(int i=0; i<positions; i++) 
        arr[rnd.nextInt(n)][rnd.nextInt(n)] = 1; // Inserir os valores aqui
}
    
07.04.2018 / 22:40