在此示例中,它打印出学生的姓名并将用户从键盘输入的内容记入 Vector。
但我只想打印出超过 30 个学分的向量。
谢谢你的帮助。
public class Main {
public static void main(String[] args) {
Teacher t = new Teacher("Prof. Smith", "F020");
Student s = new Student("Gipsz Jakab", 34);
Vector<Person> pv = new Vector<Person>();
pv.add(t);
pv.add(s);
Scanner sc = new Scanner(System.in);
String name;
int credits;
for (int i=0;i<5;i++){
System.out.print("Name: ");
name = sc.nextLine();
System.out.print("Credits: ");
credits = sc.nextInt();
sc.skip("\n");
pv.add(new Student(name, credits));
}
System.out.println(pv);
System.out.println("The size of the Vector is: " + pv.size());
}
}