2012年5月31日 星期四

Java Basic(34)-Table for Multidimensional Arrays多維列陣


class apples{
public static void main(String args[]){
int firstarray[][]={{8,9,10,11},{12,13,14,15}};
int secondarray[][]={{30,31,32,33},{43},{4,5,6}};
System.out.println("This is the first array");
display(firstarray);
System.out.println("This is the second array");
display(secondarray);
}
public static void display(int x[][]){
for(int row=0;row<x.length;row++){ → loop for 第一[]
for(int colume=0;colume<x[row].length;colume++){ → loop for []
System.out.print(x[row][colume]+"\t");
}
System.out.println();
}
}
}


Program將運行這樣的:

This is the first array
8 9 10 11
12 13 14 15
This is the second array
30 31 32 33
43
4 5 6

沒有留言:

張貼留言