Multi dimensional array

Multi dimensional array

Multi dimensional arrays represent 2D,3D… arrays which are combination of several earlier types of arrays.

Syntax to declare multi dimensional array
dataType[][] arrayname; (or)
dataType [][]arrayname; (or)
dataType arrayname[][]; (or)
dataType []arrayname[];

Instantiation of an multi dimensional array
int[][] arr=new int[2][2];

Program of multi dimensional array
class test
{
public static void main(String args[])
{
int arr[][]={{1,2,3},{4,5,6},{7,8,9}};
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(arr[i][j]+” “);
}
System.out.println();
}
}
}

Output:
1 2 3
4 5 6
7 8 9

 

Leave a Reply

Your email address will not be published. Required fields are marked *