How do I set certain array values for the same value? (Java)

Asked

Viewed 42 times

0

Example, I have a two-dimensional array of type int:

int array[][] = new int[10][10];

How do I define the value of, for example [2][3], [6][7] and [1][9] for some same int, without needing to define one at a time like this:

array[2][3] = -1;
array[6][7] = -1;
array[1][9] = -1;
  • 1

    why do you need to do this? what are you implementing?

1 answer

1

Somehow you will need to inform the specific positions in which you want the same value. So, a small optimization would be this way.

 array[2][3] =  array[6][7] =  array[1][9] = -1;

Browser other questions tagged

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