Multidimensional Arrays
A two-dimensional array is an array whose elements are arrays. The first index chooses a row, and the second chooses a column within that row.
In Java, rows may have different lengths, so the inner loop should use seats[row].length rather than assuming every row is the same size.
Visit every seat
public class Main {
public static void main(String[] args) {
String[][] seats = {
{"A1", "A2", "A3"},
{"B1", "B2"}
};
for (int row = 0; row < seats.length; row++) {
for (int column = 0;
column < seats[row].length;
column++) {
System.out.println(seats[row][column]);
}
}
}
}
Output:
A1
A2
A3
B1
B2
The outer loop selects a row. The inner loop visits every seat in that row. The second row is shorter, and its own length keeps the loop inside its bounds.
seats.length is the number of rows, not the total number of values across all rows.
Use both indexes to total the sales for each day in the two-dimensional array.