public?void?testRemove(){
System.out.println("請輸入待刪除學生的id");
Scanner?console?=?new?Scanner(System.in);
????String?id?=?console.next();
????while(true){
????//通過Map的get(key)得到的value值判斷該id是否存在
????Student?st?=?students.get(id);?
???? if(st?==?null){
???? System.out.println("這個id并不存在!請重新輸入");
???? continue;
????}else{
???? System.out.println("待刪除學生id為"+students.get(id).id+"待刪除名字為"+students.get(id).name);
????students.remove(id);
????System.out.println("成功刪除學生!");
????break;
???
????}
????
????}
}學生id里面有1、2和3,當選擇刪除id為4時程序陷入了死循環,請教下大家原因在哪里
添加回答
舉報
0/150
提交
取消