## two Dimensioanl Array in Java

Java, supports multi-dimensional arrays - 1-dimensional, 2-dimensional, 3-dimensional. But we mostly use one and two dimensional arrays. Use of the 3 d and more dimensional array is rare. But once you understand the concept of the 2-dimensional array, you can extend the concept for 3 or more dimension case as well.

You can visualize a 2-dimensional array as a table with rows and columns. From machine perspective the row and colunms are just ideas as they do nor exist in reality. What happens on a machine is - we store the first row followed immediately by the second row and so on - in a linear fashion. We call a 2-dimensional array as an Array of Array.

The example below shows a two dimensional array, where a student records the number of hours he studied in each of the three weeks. We then calculate the total number of hours read by the student.

 ` /*  ReferenceDesigner.com Java Tutorial  understanding Two dimensional arrays  */  class twodarray{ public static void main (String args[]) {  int[][] hoursread = new int; // Two rows 7 columns int i,j,totalhoursread =0;   // Assigning values to the first row  hoursread = 2; hoursread = 1; hoursread = 3; hoursread = 5; hoursread = 4; hoursread = 1; hoursread = 0;   // Assigning values to the first row  hoursread = 3; hoursread = 1; hoursread = 2; hoursread = 6; hoursread = 3; hoursread = 2; hoursread = 1;    for ( i=0; i<=1; i++) { for (j=0; j<=6; j++) totalhoursread += hoursread[i][j]; } System.out.println(" Total Hours Read = " + totalhoursread); }  }`

If you compile and run, you get the following output

 ` Total Hours Read = 34`

A 2x3 dimensional array x can me mentally thought of as being composed of two rows an three columns.

Table: A two dimensional array x

 x x x x x x