+ 2

how to loop multi array in java?

thanks

26th Jan 2018, 12:29 AM
Geraldine Omay Rusiana
Geraldine Omay Rusiana - avatar
3 Respuestas
+ 4
public class Program { public static void main(String[] args) { int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; for(int x=0; x<myArr.length; x++){ for(int y=0; y<myArr[x].length; y++) System.out.print(myArr[x][y] +" "); System.out.println(); } } }
26th Jan 2018, 1:09 AM
Harjeet Singh
Harjeet Singh - avatar
+ 3
thank you guys <3
26th Jan 2018, 4:08 AM
Geraldine Omay Rusiana
Geraldine Omay Rusiana - avatar
+ 1
Or you can use the For each or enhanced for loop like this: for(int[] subarray : myArr) { for (int element : subarray) { System.out.print(element); } System.out.println(); }
26th Jan 2018, 1:46 AM
Michelle Dougenik
Michelle Dougenik - avatar