+4

How to display multi-dimensional array elements in java using enhanced for loop ?

5/16/2019 2:32:00 PM

H...G....!

2 Answers

New Answer

+2

https://stackoverflow.com/questions/18931332/enhanced-for-loop-for-2d-array-in-java

+1

Let's suppose you have a 2D int array: int[][] arr = new int[2][5]; To display its elements with an enhanced loop you just have to this. for (int[] i:arr){ for (int j:i){ System.out.println(j); } } If you need to make a 3D or a 4D array remember that just the last loop is going to take directly the values, so it's the only one that will be like this: for(int x:y) The previous have to be like this: for(int[] a:b) because you're not taking int values at first, but int arrays.