public class Array {
public static void main(String[] args) {
int[] arr01 = new int[10];
String[] arr02 = new String[5];
arr01[0] = 0;
arr01[1] = 1;
arr01[2] = 2;
for (int i = 0; i < 10; i++) {
arr01[i] = 10 * i;
System.out.println(arr01[i]);
}
System.out.println("#############");
for (int m : arr01) {
System.out.println(m);
}
Sir[] arr03 = new Sir[3];
arr03[0] = new Sir(1001, "韩一");
arr03[1] = new Sir(2002, "韩二");
arr03[2] = new Sir(3003, "韩三 ");
for (int j = 0; j < arr03.length ; j++) {
System.out.println(arr03[j].getId());
System.out.println(arr03[j].getName());
}
}
}
class Sir {
private int id;
private String name;
public Sir(int id, String name) {
this.id=id;
this.name=name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
运行结果
0
10
20
30
40
50
60
70
80
90
#############
0
10
20
30
40
50
60
70
80
90
1001
韩一
2002
韩二
3003
韩三