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]); } } } }
3 Respuestas
+ 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
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.
0
Gustavo Farina , you are welcome.