0
Is that code for multidimensional array in Java really working for any suitable case within the arrays?
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.length; i++) { for(int k = 0; k < matrix[i].length; k++) { System.out.println(matrix[i][k]); } } } }
3 Answers
+ 2
What did you mean by "suitable case within the array"?
+ 1
For example when the length of any of the arrays within the main array is longer or shorter than the others.
The task was to create a code to print out every single element of the whole multidimensional array, but the solution for that task only used 'i < 3' & 'k < 3' for the conditions of the loops.
0
Sorry but apparently I still am failing to understand what your doubt was about.
The one problem I see in that snippet is the use of println( ) for displaying the matrix's content. println( ) inserts a new line after printing the data, but I think that's not what we want to see, so use of print( ) is rather preferable.
Here's some ways to printing matrices, hope it helps. You're welcome to confirm in case of any doubt.
All these are available in Java tutorials BTW ...
https://code.sololearn.com/cYAV7QNoKEs9/?ref=app