+ 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

16th Oct 2018, 2:20 AM
Franklin Valero
Franklin Valero - avatar
2 Answers
+ 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)
16th Oct 2018, 5:38 AM
Daniele Bonomi
Daniele Bonomi - avatar
+ 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
16th Oct 2018, 5:50 AM
Ipang