1
Having the array of arrays:
int matriz[][] = new int[1][1]
How do I use for each (for(int Count : array)) to traverse your rows and columns?
1
Having the array of arrays:
int matriz[][] = new int[1][1]
How do I use for each (for(int Count : array)) to traverse your rows and columns?
4
The namer to traverse 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;
}
}
Note that in this way, all rows and columns of the matrix are traversed and accessed by the variable elemento
.
Note that the outermost loop returns a vector of a dimention per iteration and the innermost loop returns an element, again by iteration. In this way, the whole vector is traversed.
Browser other questions tagged java matrix foreach
You are not signed in. Login or sign up in order to post.
Thanks for the feedback, but I was wondering how to do this using "for each", that "for(int i : array)".
– rodrigom
Oops! Give me a few minutes
– EduardoFernandes
All right, thank you.
– rodrigom
Please, if the answer is correct, mark the green "check" that appears below the response counter. Thank you :)
– EduardoFernandes