Multidimensional Array Challenge - Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Multidimensional Array Challenge - Java

Hi All, My first post here. I can't, for the life of me, find where the bug is on this code. All I'm trying to do it print each value in the arrays on a separate line using a nested for loop. Help please! Thanks public class Main { public static void main(String[] args) { int[][] matrix = { {8, 1, 6}, {3, 5, 7}, {4, 9, 0}, }; //output the numbers for (int i = 0; i < matrix.lenght; i++) { for (int x : matrix [i]) { System.out.println(matrix[i][x]); } } } }

31st Dec 2020, 12:05 PM
Gustavo Farina
Gustavo Farina - avatar
3 Answers
+ 3
Gustavo Farina , first change "lenght" to "length". Then when you print => System.out.println(x) ; Look at the code. https://code.sololearn.com/cPLq8A641RK2/?ref=app
31st Dec 2020, 12:11 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Thank you! I was under the impression that in an enhanced for loop, the x referred to the index, not the value itself. Makes sense now.
31st Dec 2020, 12:44 PM
Gustavo Farina
Gustavo Farina - avatar
0
Gustavo Farina , you are welcome.
31st Dec 2020, 12:47 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar