forked from JustinSDK/JavaSE6Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewArrayDemo2.java
More file actions
28 lines (23 loc) · 776 Bytes
/
NewArrayDemo2.java
File metadata and controls
28 lines (23 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package onlyfun.caterpillar;
import java.lang.reflect.Array;
public class NewArrayDemo2 {
public static void main(String[] args) {
Class c = String.class;
// 打算建立一個3*4陣列
int[] dim = new int[]{3, 4};
Object objArr = Array.newInstance(c, dim);
for(int i = 0; i < 3; i++) {
Object row = Array.get(objArr, i);
for(int j = 0; j < 4; j++) {
Array.set(row, j, "" + (i+1)*(j+1));
}
}
for(int i = 0; i < 3; i++) {
Object row = Array.get(objArr, i);
for(int j = 0; j < 4; j++) {
System.out.print(Array.get(row, j) + " ");
}
System.out.println();
}
}
}