Single Dimentional Array
|
Double Dimentional Array
|
To use a multi-dimentional array, you must do the same three steps as with all arrays.
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]; } } |
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() {
public
void paint(Graphics q) {
public
boolean mouseDown(Event ignored, int mousex, int mousey) {
|