How do I define certain values of an array for the same value? (Java)

0

Example, I have an array of two dimensions of type int:

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

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

array[2][3] = -1;
array[6][7] = -1;
array[1][9] = -1;
    
asked by anonymous 22.04.2017 / 19:06

1 answer

1

In some way you will need to inform the specific positions where you want the same value. So a small optimization would be this way.

 array[2][3] =  array[6][7] =  array[1][9] = -1;
    
22.04.2017 / 19:09