+ 1
Explicación array position
public class Program { public static void main (String [] args) { int [] [] sample = {{1, 2, 3}, {4, 5, 6}}; int x = sample [0] [2]; System.out.println (x); } } // I see it as an index. 0 indicates the array in question and 2 the value of the position in the array
2 Respostas
+ 2
This is a matrix (or multidimensional array)
int[] [] sample = {
{1,2,3},
{4,5,6}
};
sample[0][2] means the third element of the first array (3)
+ 2
In that code 0 refer to row index, and 2 refer to column index. For easier understanding you can write the array declaration in separate lines, as follows;
int [][] sample ={
{1,2,3}, // 1st row (sample[0])
{4,5,6} // 2nd row (sample[1])
};
for each row you can also refer to the columns by index. Each row contains 3 columns, remember index starts with zero;
| Row ↓ | 0 | 1 | 2 | → Column
| 0 | 1 | 2 | 3 |
| 1 | 4 | 5 | 6 |
Hth, cmiiw