在這個例子中,它打印出學生的姓名和學分用戶從鍵盤輸入到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());
}
}
使用'if'聲明 –
使用GET(.. )來獲取值並使用if進行比較。 –
用戶可以輸入任何字符串作爲信用? – BBdev