Hi i have created multidimension array and accessed the values using for loop? how can we do using for-each loop?
class MultiArray
{
int arr[][];
public MultiArray()
{
arr = new int[][]{{1,2,3},{4,5,6,7},{8,9,10,11,12}};
}
public void forLoop()
{
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr[i].length;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
public static void main(
String[] args)
{
MultiArray ma = new MultiArray();
ma.forLoop();
}
}