RT,求高手相助,实在查不到arraylist在这要求下该怎么用 ------最佳解决方案-------------------- import java.util.*;
class Student{
private String name="a";
private String sex="aa";
private String major="aaa";
private String graduateSchool="aaaa";
}
public class Duo {
public static void main(String[] args) {
System.out.println("输入具有N个学生的集合:");
Scanner r1=new Scanner(System.in);
int a=r1.nextInt();
ArrayList students = new ArrayList();
for(int i=0;i<a;i++){
System.out.println("请输入学生的信息姓名、性别、专业、毕业院校,每输入一个换行再输入:");
Scanner r2=new Scanner(System.in);
String b=r2.next();
String c=r2.next();
String d=r2.next();
String e=r2.next();
students.add(b);
students.add(c);
students.add(d);
students.add(e);
}
int j=1;
System.out.println("第"+j+"个学生的信息是:");
for(int i=0;i<students.size();i++){
if((i+1)%5==0){
j++;
System.out.println("第"+j+"个学生的信息是:");
}
System.out.println(students.get(i)+" ");
}
}
}
不知道符不符合你的意思。。。 ------其他解决方案-------------------- 不知道这样算不算符合你的要求?
public class Student implements Serializable {
private String name;
private String gender;
private String major;
private String graduateSchool;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getGraduateSchool() {
return graduateSchool;
}
public void setGraduateSchool(String graduateSchool) {
this.graduateSchool = graduateSchool;
}
}
public class List {
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<Student>();
Student student = new Student();
student.setName("tom");
student.setGender("male");
student.setMajor("SE");
student.setGraduateSchool("MIT");
students.add(student);
}
}