相关疑难解决方法(0)

使用try/catch时无休止的循环问题

我有一个while循环,它应该捕获一个非int输入并要求用户重新输入一个int.然而,它只是无休止地循环错误消息.有没有人知道为什么第二次不允许扫描仪输入?

  while(!enteredInt)
  {
      try
      {
          locus = input.nextInt();
          enteredInt = true;
      }
      catch (Exception e)
      {
          //user didn't type an integer
          System.out.println("You didn't enter a valid number, re-enter point where you will build your city");
      }
  }
Run Code Online (Sandbox Code Playgroud)

java exception

0
推荐指数
1
解决办法
2171
查看次数

标签 统计

exception ×1

java ×1