0
how do we use for loop in multi dimensional arrays ? Please explain with a simple example thanks
2 Respuestas
+ 2
http://code.sololearn.com/cSQemDqPlEz4
public class Program
{
public static void main(String[] args) {
int[][][] arr = new int[][][] { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } };
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
for (int k = 0; k < arr[i][j].length; k++) {
System.out.print(arr[i][j][k]);
}
System.out.println();
}
System.out.println();
}
}
}
+ 1
say if u hv two dimensional array .. then u can first for loop for row and second for loop for column .. and then u can add any work in loop . !! hope dat helps !!