Create an array
The following array with space to store 3 integers
int [] grid = new int[3];
int [] grid = new int[3];
Create a 2D Array
The following array has 2 rows and 3 columns. It has space to store 6 integers:
int [] [] grid = new int[2][3];
int [] [] grid = new int[2][3];
Assign Values
The following code will set all spaces in the 2D array to 99 using a nested loop.
for (int row = 0; row < grid.length; row++)
{
for (int col = 0; col < grid[0].length; col++)
{
grid[row][col] = 99;
}
}
for (int row = 0; row < grid.length; row++)
{
for (int col = 0; col < grid[0].length; col++)
{
grid[row][col] = 99;
}
}