public class Test {
public static void main(String[] args) {
Person[] p = new Person[2];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < p.length; i++) {
Person per = p[i];
System.out.println("输入学生的姓名");
per.name = sc.nextLine();
System.out.println("输入学生的年龄");
per.age = sc.nextInt();
System.out.println("输入学生成绩");
per.score = sc.nextDouble();
}
System.out.println(p[1].name);
}
}作者: Jarc 时间: 2016-9-9 13:24
问题出在Person per = p[i];你的p[i]只是一个数组的第几个成员,但是其中并没有放入学生。应该是p[i]= new person(参数);