I'm preparing for the Java OCA exam but there are several tricky questions about how iterates a multidimensional array. So, if I had this array and I wanted to iterate using the for and for-each loops what would all be ways to do it? I usually used only these three:
int [][]matrix = {{3,4,5},{6,7,8},{9},{10,11,12}};
//First way
for (int [] a : matrix){
for (int i =0; i<a.length;i++){
//code
}
}
//Second way
for (int []a: matrix){
for (int i: a){
//code
}
}
//Third way
for (int i = 0; i<matrix.length; i++) {
for (int j=0; j<matrix[a].length; j++) {
//code
}
}
//Fourth way???
Thanks a lot!