
take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below.........

import java.util.*;
class Display2dArrayUsingOneLoop{
public static void main(String args[]) {
int j=0,k=0,a[][]={ {1,2,4}, {5,6,7}};
while(true) {
System.out.print(a[j][k] + " ");
if (a[j].length == k + 1) {
k = 0;
j++;
System.out.println();
} else {
k++;
}
if(a.length == j) {
break;
}
}
}
}