• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to access the elements of multidimension array using for each loop?  RSS feed

 
awad saleh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
 
Kuba Zygmunt
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
awad saleh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kuba Zygmunt.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!