Question 5 10 points Describe an application that would be a
Question 5 (10 points)
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
Multidimensional arrays are used to store information in a matrix form -- e.g. a railway timetable, schedule cannot be stroed as a single dimensional array.
You may want to use a 3-D array for storing height, width and lenght of each room on each floor of a building.
Mostly we need multidimensional array to stroe image related data because to represent image we need three 3D space to store pixels, so they are extensibly used in movie, animation etc.
Java code to create 3D matrix and take input:
import java.util.Scanner;
public class Three3DArray {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// creating 3D array of type int to store pixels of an image
int[][][] image = new int[4][5][6];
// filling data
for(int i=0; i<image.length; i++){
for(int j=0; j<image[i].length; j++){
for(int k=0; k<image[i][j].length; k++){
image[i][j][k] = sc.nextInt();
}
}
}
}
}

