try/catch with InputMismatchException creates infinite loop

前端 未结 7 1011
醉话见心
醉话见心 2020-11-22 13:27

So I\'m building a program which takes ints from user input. I have what seems to be a very straightforward try/catch block which, if the user doesn\'t enter an int, should

7条回答
  •  醉话见心
    2020-11-22 13:49

    another option is to define Scanner input = new Scanner(System.in); inside the try block, this will create a new object each time you need to re-enter the values.

提交回复
热议问题