Having the arrays array:
int matriz[][] = new int[1][1]
How do I use the for each (for (int count: array)) to traverse its rows and columns?
Having the arrays array:
int matriz[][] = new int[1][1]
How do I use the for each (for (int count: array)) to traverse its rows and columns?
The name of traversing the array using foreach is as follows:
int matriz[][] = new int[1][1];
int valorRecebido = 0;
for (int[] vetor : matriz) {
for (int elemento : vetor) {
valorRecebido = elemento;
}
}
Notice that in this way, all rows and columns of the array are traversed and accessed by the variable elemento
.
Note that the outermost loop returns a vector of one dimension per iteration, and the innermost loop returns one element, again by iteration. In this way, every vector is traversed.