接收InputMismatchException

时间:2018-06-02 07:03:54

标签: java java.util.scanner inputmismatchexception

我尝试为我的作业编写hashmap代码。试图添加(删除和搜索) 当我运行程序并选择删除或搜索时出现此错误:

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Task6.sultan(Task6.java:63)
at Task6.main(Task6.java:83)

我的代码:

case 2:
System.out.println(" Delete Car Details : ");
 x.nextLine();
 key = x.nextLine();
 Integer v = a.get(key);
  if(v == null)
  System.out.println("No Details exists for That Car "+key);
 else
 {
 a.remove(key);
 System.out.println("Car Details ("+key+","+v.intValue()+") Removed. 
 \n");
 }
  break;
 case 3:
 System.out.print("Enter Car Details To Search : ");
   Value = x.nextInt();
  for(Map.Entry<String,Integer> entry : a.entrySet() )
    { 
  System.out.println("( "+entry.getKey()+" , "+entry.getValue()+" );");
    }
       break;

0 个答案:

没有答案