Scanner賦值問(wèn)題
System.out.println("成功添加學(xué)生:" + students.get(ID).name);
按照這句話輸出,學(xué)生姓名一直是null,這是為什么?直接把?students.get(ID).name換成newname,就可以輸出了。這是為什么??有人知道嗎?
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-06-15
搞掂了,原來(lái)是Student類(lèi)中的構(gòu)造方法初始化出現(xiàn)問(wèn)題、