Multi-Dimentioned Arrays!!

Arrays can have more than one dimention.  In fact, there is no reasonable limit to the number of dimentions an array can have.  If a one dimentional array (the old kind) can be thought of as a list then a two dimentional array can be thought of as a grid, like a checkerboard or a spreadsheet.
Single Dimentional Array
Red Green Blue Orange Brown
 
Double Dimentional Array
Red Green Blue
Blue Green Brown
Orange Violet Green
 

To use a multi-dimentional array, you must do the same three steps as with all arrays.

The size of a multi-dimentioned array is the product of the size of each dimention multiplied together.  For example, if the array has dimentions of size 10, 20, and 30 then the array has 600 elements!

Here are some sample algorithms:
 
Find the largest element of an array
max = num[0][0];
for(i = 0; i < SIZE1; i++) {
      for(j = 0; j < SIZE2; j++) {
           if (max < num[i][j]) {
                 max = num[i][j];
           }
       }
}
Sum all elements of an array
sum = 0;
for(i = 0; i < SIZE1; i++) {
      for(j = 0; j < SIZE2; j++) {
           sum+=num[i][j];
       }
}
Here is a program that puts up a grid of colors.  Everywhere you click, the color changes.  This lets you draw and figure you want.
 
import java.awt.*;
public class grid extends java.applet.Applet {

        Color grid[][]; // the main gridarray
        int x, y;       // where they clicked
        int i,j;        // index for for loops

        public void init() {
                grid = new Color [20][20];
                for(i = 0; i < 20; i++ ) {
                        for(j = 0; j< 20; j++ ) {
                                grid[i][j] = Color.green;
                        }
                }
        }

        public void paint(Graphics q) {
                for(i = 0; i < 20; i++ ) {
                        for(j = 0; j< 20; j++ ) {
                                q.setColor(grid[i][j]);
                                q.fillRect(i*20,j*20,20,20);
                                q.setColor(Color.black);
                                if (grid[i][j] == Color.green) {
                                        q.drawString("G", i*20+10, j*20+10);
                                }
                                else {
                                        q.drawString("R", i*20+10, j*20+10);
                                }
                        }
                }
        }

        public boolean mouseDown(Event ignored, int mousex, int mousey) {
                x = mousex / 20;
                y = mousey / 20;
                if (grid[x][y] == Color.green) {
                        grid[x][y] = Color.red;
                }
                else {
                        grid[x][y] = Color.green;
                }
                repaint();
                return true;    // required for all boolean functions
        }
}