Multidimensional arrays are very useful while programming. Matrix operations become easier when using arrays.
|
Code:
|
String[][] array = new String[2][4];
for (int row=0;row<2;row++)
{
for (int col=0;col<4;col++)
array[row][col] = "Value at row: " + row + " col: " + col;
}
for (int row=0;row<2;row++)
{
for (int col=0;col<4;col++)
System.out.println(array[row][col]);
} |
Output:
|
Code:
|
Value at row: 0 col: 0
Value at row: 0 col: 1
Value at row: 0 col: 2
Value at row: 0 col: 3
Value at row: 1 col: 0
Value at row: 1 col: 1
Value at row: 1 col: 2
Value at row: 1 col: 3 |