+ 1

What is the error in this code?

I want to extract all the elements of this multidimensional array.. public class Program { public static void main(String[] args) { int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; for(int x : myArr) { System.out.println (x) } } }

12th Aug 2018, 12:43 PM
Kavya R
Kavya R - avatar
3 Answers
+ 1
you don't have a semicolon at the end of system.out.println(x) Edit: You also need to add a [] where the int x is, also add another for each loop, for example: for(int []x : myArr){ for(int y: x){ System.out.println(y); } System.out.println(); }
12th Aug 2018, 2:48 PM
Paul Yan
Paul Yan - avatar
14th Aug 2018, 9:40 PM
Paul Yan
Paul Yan - avatar
0
okay...but i didn't understand "also add another for each loop"!! also i am not getting it while coding..will u please code it and send it to me!!! please
13th Aug 2018, 6:09 AM
Kavya R
Kavya R - avatar