Two dimensional arrays allow the programmer to store and access data in rows and columns of a grid.
// Initializes a 3 by 2 array of integers and prints its contents
public class Test2dArray{
public static void main(String[]args){
// Create the array and set its contents to 1-6
int [][] array = new int[3][2];
int data = 1;
for (int row = 0; row < array.length; row++)
for (int column = 0; column < array[row].length; column++){
array[row][column] = data;
data++;
}
// Print the contents of the array in grid format
for (int row = 0; row < array.length; row++){
for (int column = 0; column < array[row].length; column++)
System.out.print(array[row][column] + " ");
System.out.println();
}
}
}