Drawing of positions of a matrix

Asked

Viewed 126 times

-2

I need to create a function to draw within a matrix full of 0 with size n x n, four positions to modify the value only of these drawn positions.

  • 1

    What do you already have of this function ready? We can help you build your function based on what you have already done

1 answer

0

Uses the class java.util. and then something like this:

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
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.