It's very useful to define constants for the number of rows and columns.
static final int ROWS = 2;
static final int COLS = 3;
. . .
int[][] board = new int[ROWS][COLS];
Many row and column indexes (indices is the traditional English plural) have a meaning, and aren't just simply arbitrary numbers. The following example might be used to represent the number of accidents on by day of the month and the hour of the day. See programming problems below for some examples using this array.
static final int DAYS = 31;
static final int HOURS = 24;
. . .
int[][] accidents = new int[DAYS][HOURS];
No comments:
Post a Comment