搓搓的代码
1 import java.util.ArrayList; 2 import java.util.Iterator; 3 class Student{ 4 private static int num; 5 private String name; 6 private int age; 7 private int number; 8 public Student(){} 9 public Student(String name,int age) { 10 num++; 11 this.number=num; 12 this.name=name; 13 this.age=age; 14 } 15 public void setName(String name) { 16 this.name=name; 17 } 18 public String getName() { 19 return name; 20 } 21 public void setAge(int age) { 22 this.age=age; 23 } 24 public int getAge() { 25 return age; 26 } 27 public int getNumber() { 28 return number; 29 } 30 } 31 public class Main{ 32 public static void main(String[] args) { 33 Student[] arr=new Student[5]; 34 arr[0]=new Student("张三",19); 35 arr[1]=new Student("李四",18); 36 arr[2]=new Student("王五",18); 37 for(int i=0;i<3;i++) { 38 System.out.println(arr[i].getName()+" "+arr[i].getAge()+" "+arr[i].getNumber()); 39 } 40 /* 41 ArrayList<String> t =new ArrayList<String>(); 42 t.add("abc"); 43 t.add("1551"); 44 Iterator<String> it = t.iterator(); 45 while(it.hasNext()) { 46 Object obj=it.next(); 47 System.out.println(obj); 48 } 49 */ 50 /* 51 ArrayList list = new ArrayList(); 52 list.add("str"); 53 list.add(123); 54 Iterator it =list.iterator(); 55 while(it.hasNext()) { 56 Object obj=it.next(); 57 System.out.println(obj); 58 } 59 */ 60 61 62 } 63 }