public void testMapRemove()
{
Scanner scanner=new Scanner(System.in);
while(true)
{
System.out.println("请输入想要删除学生的ID");
String ID=scanner.next(); //报错行
Student stu=map.get(ID);
if(stu!=null){
map.remove(ID);
System.out.println("成功删除学生"+map.get(ID).name);
break;
}
else
{
System.out.println("该ID不存在!");
continue;
}
}
}
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at com.imooc_collection.SetMap.testMapRemove(SetMap.java:50)
慕少7573967
相关分类