38
Question Question 32
What do you understand by two-dimensional arrays ? State some situations that can be easily represented by two-dimensional arrays.
A two-dimensional array is an array in which each element is itself an array. For instance, an array A[M][N] is an M by N table with M rows and N columns containing M x N elements.
The general form of a two-dimensional array declaration in Java is as follows:type array-name[ ][ ] = new type[rows][columns];
Some situations that can be easily represented by two-dimensional arrays are as follows:
- In a school, marks obtained by a student in various subjects can be stored in a two-dimensional array, where rows can be used for successive tests (mid term, quarterly, half yearly etc.) and columns can be used for subjects (maths, english, science, hindi, computer etc.).
- In a business, the sales for a month can easily be represented using a two-dimensional array, where rows can represent weeks and columns can represent the individual days in a week.