 Consider this table of quarterly sales over three years. It's a two-dimensional table with rows and columns. Here's how we represent it in Java. We use two sets of square brackets instead of one, and we put each row of the table in its own set of braces. You might be thinking, that looks a lot like an array that has three arrays in it, and you'd be entirely correct. Here's what's happening behind the scenes. Sales is a reference to an array of length three, as there are three rows, and each item in that array is a reference to another array that has the elements for that row. That means that if we ask for the length of the sales array, we'll get three. Let's go to a Java program and try it. We'll do system.out.printline. Length of sales is plus sales.length. Compile it and run it, and the length of the sales is three. If we want to find out how many columns the array has, we look at the length of one of its rows. Let's find the number of columns in row zero is sales sub zero, which is the first sub array, and its length. And let's run it, and the number of columns in row zero is four. In this array, all our rows have the same number of elements, but because of the way Java stores 2D arrays, there's no law that says that rows must have equal length. To access an individual element of an array, you need to use two sets of square brackets with the row number first, then the column number. Sales sub zero two is row zero column two, and sales sub two one is row two column one. Now let's write code to get the grand total of the numbers in the array. We'll set our grand total to zero, and then I'll need a nested loop. The outer loop will iterate through the rows. For int row equals zero, row less than sales dot length, row plus plus. Notice that I'm using row as my counter variable rather than i. This makes the code much more understandable. My inner loop will iterate over the columns. For column equals zero, column less than sales sub row dot length, remember the number of items in each sub array is the number of columns, and then we'll add one to the number of columns, and inside this nested loop we'll set the grand total to be the previous value plus the item at the given row and column. Once we're out of the loop, we print the grand total properly labeled, and I'll use printf for that. The grand total is dot and with 0.2f, so it looks like a monetary format, and grand total. Let's recompile and rerun it, and the grand total is 186. Now let's get the yearly totals. We'll set a constant base year to be our first year, 2016, and in this loop we're going to iterate over the rows, because each row represents a year, and at this point we set our yearly total to zero. Unlike the grand total, we have to set the yearly total to zero at the beginning of each year. Then we can run our column loop. For column equals zero, column less than sales sub row dot length, column plus plus, our yearly total will be incremented by the sales for the given row and column. After we've processed a row, we print its results. Total for the year is, and the year will be the base year plus the row, and the yearly total. The print on lines 27 and 28 is inside the row loop. We need to print this after we process each row. Let's compile and let's run. And there are our yearly totals. Finally, we'll have another nested loop to print our quarterly results. This time the outer loop will iterate over the column, because each column represents a quarter. For int column equals zero, column less than sales sub zero dot length, and I'm using row zero here because all of my rows happen to be the same length. In this case I'm going to set my quarterly total to zero at the beginning of each column, and then I'll go down the rows for that column. And my quarterly total, plus and becomes sales row column. It's important to note that when you access the array element, you always put the row first. Even though your outer loop may be going over the columns first, you always access an element in the array by its row, and then its column. At the end of processing each column, we'll print the quarterly result. The total for quarter is... we'll fill in the column plus one. Remember our column goes zero, one, two, three, but humans expect to see Q1, Q2, Q3, and Q4, and our quarterly total. Let's save that and compile and run. And that's what you need to know to work with multi-dimensional arrays.