package arraysofobjects;
import java.util.Scanner;
public class arraysofobjects {
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
students[] stu=new students[4];
String name;
int grade;
for(int i=0;i<stu.length;i++)
{
name=input.nextLine();
grade=input.nextInt();
stu[i]=new students(name,grade);
}
for(int i=0;i<stu.length;i++)
{
System.out.printf("name:%s\tgrades:%d\n",stu[i].name(),stu[i].grades());
}
}
}
package arraysofobjects;
public class students {
private String _name;
private int _grades;
public students(String name,int grades)
{
this._name=name;
this._grades=grades;
}
public String name()
{
return this._name;
}
public int grades()
{
return this._grades;
}
}
输入两行就开始报错了