Re: multi dimension arrays
A multi-dimensional array of dimension n (i.e., an n-dimensional array or simply n-D array) is a collection of items which is accessed via n subscript expressions. For example, in a language that supports it, the tex2html_wrap_inline60030 element of the two-dimensional array x is accessed by writing x[i,j].
The Java programming language does not really support multi-dimensional arrays. It does, however, support arrays of arrays. In Java, a two-dimensional array x is really an array of one-dimensional arrays:
int[][] x = new int[3][5];
The expression x[i] selects the ith one-dimensional array; the expression x[i][j] selects the jth element from that array.
The built-in multi-dimensional arrays suffer the same indignities that simple one-dimensional arrays do: Array indices in each dimension range from zero to lenght - 1 , where length is the array length in the given dimension. There is no array assignment operator. The number of dimensions and the size of each dimension is fixed once the array has been allocated.
Re: multi dimension arrays
#include <iostream>
using namespace std;
// DECLARATIONS
void printArray (int arg[][3][3], int i, int j, int k)
{
cout << "\n";
for (int n = 0 ; n < i ; n++)
{
for (int m = 0 ; m < i ; m++)
{
for (int l = 0 ; l < i ; l++)
{
cout << " " << arg[n][m][l] << " ";
}
cout << "\n";
}
cout << "\n";
}
cout << "\n";
}
int main ()
{
// INPUT
int array1[3][3][3] = { { { 1, 2, 3}, { 4, 5, 6}, { 7, 8, 9} },
{ {10, 11, 12}, {13, 14, 15}, {16, 17, 18} },
{ {19, 20, 21}, {22, 23, 24}, {25, 26, 27} }
};
// CALCULATIONS
// OUTPUT
printArray(array1, 3, 3, 3);
// EXIT
cout << "\n done.\n";
return 0;
}