1/8
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Two Dimensional Arrays
A collection of data that is stored in a table or grid, with rows and columns.
Rows
Horizontal
Columns
Vertical
declaration statement
datatype[][] nameOfArray = new dataType[][];
int[][] myTable = new int [4][7];
remember
first spot starts at 0
go down first, then to the side
when declaring, it counts normally
when choosing a spot, start from 0
grid.length
the number of rows
grid [0].length
number of columns
Traversing
for (int r = 0; r < myTable.length; r++ )
{
for (int c = 0; c < myTable[0].length; c++)
{
system.out.println(myTable[r][c]);
}
}
Populating with an initializer list
int [][] grid = { { 5, 2, 12, -4, 95} , //row 0
{ 33, 59, 23, 68, 200}, //row 1
{ 42, 87, -99, 312, 0} } ; //row 2