運(yùn)行程序添加學(xué)生后,為什么顯示已添加的學(xué)生顯示的是ID而不是姓名
public void testPut() {
// 創(chuàng)建一個(gè)Scanner對(duì)象,用來(lái)獲取輸入的學(xué)生ID和姓名
Scanner console = new Scanner(System.in);
int i = 0;
while (i < 3) {
System.out.println("請(qǐng)輸入學(xué)生ID:");
String ID = console.next();
// 判斷該ID是否被占用
Student st = students.get(ID);
if (st == null) {
// 提示輸入學(xué)生姓名
System.out.println("請(qǐng)輸入學(xué)生姓名:");
String name = console.next();
// 創(chuàng)建新的學(xué)生對(duì)象
Student newStudent = new Student(ID, name);
// 通過(guò)調(diào)用students的put方法,添加ID-學(xué)生映射
students.put(ID, newStudent);
System.out.println("成功添加學(xué)生:" + students.get(ID).name);
i++;
} else {
System.out.println("該學(xué)生ID已被占用!");
continue;
}
}
}
2016-04-05
是我在Student類里面的順序搞錯(cuò)了......
2016-04-05
然而我這邊顯示的確實(shí)是學(xué)生姓名而不是ID