Saturday, July 26, 2008

Java: 2D Array Declaration

//2D Array declaration
int array1[][] = new int [2][2];

//2D Array assignment
array1[0][0] = 1;
array1[0][1] = 2;
array1[1][0] = 3;
array1[1][1] = 4;

//Print 2D Array
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
System.out.println(array1[i][j]);
}
}

No comments:


Since 26 July 2008: