Describe an application that would be a good choice for usin
Describe an application that would be a good choice for using 3D array.
Provide the size of the array and the most likely data type. Provide the specific Java nested loop
you would use to populate the array elements with random values.
Solution
There are various application for the 3D array like 3d tic-tac-toe.
Now another example is when we want to store the personAttributes of the few given number of persons.
Sex: Male | Female
Hair : Blond | Brunette | Black
Eye : Blue | Brown | Green | Hazel
Now in this we can have a 3D array storing each of the personAttributes by assigning integer to the attributes. in the 3d array.
i.e
HAIRCOLORS { BROWN = 0, BLOND = 1 ..... };
SEX { FEMALE = 0, MALE = 1 };
EYECOLORS { GREEN, BLUE, RED .... };
By assuming the \"n\" as the size of array we can say that (n^3) is the size of the array. and data type is integer.
we can use for loop for populating the 3d array with random variables.
void main(){
int boxShleve[n][n][n];
int i, j, k;
for (i=0; i<n; ++i){
for (j=0; j<n; ++j){
for (k=0; k<n; ++k){
randomNum = minimum + (int)(Math.random() * maximum);
boxShleve[n][n][n] = randomNum;
}
}
}
printf(\"%d\", boxShleve[3][4][4]);
}
