Two Dimensional ArraysArrays of ArraysCompSci 622.1Two Dimensional ArraysJust an extensions of the basic idea . . .int[][] matrix = new int[ROWS][COLS]; . . .for (int r = 0; r < matrix.length; r++) { for (int c = 0; c < matrix[0].length; c++) { . . . System.out.println(matrix[r][c]); }}CompSci 622.2Arrays of ArraysSimilar ideaWARNING: All rows the same length??? . . .String[] smith = {”Jason”, ”Sarah”, ”Oscar”, ”Ben”};String[] jones = {”Cindy”, ”Ellen”, ”Sean”, ”Betty”};String[] wells = {”Henry”, ”David”};String[][] friends = {smith, jones, wells};for (int r = 0; r < friends.length; r++) { for (int c = 0; c < friends[r].length; c++) { . . . System.out.print(friends[r][c] + ” ”); }
View Full Document