NoSuchElementException with Java.Util.Scanner

前端 未结 7 596
感动是毒
感动是毒 2020-11-22 14:38

I am very new to Java but am working through the book Java: How to program (9th ed.) and have reached an example where for the life of me I cannot figure out what the proble

7条回答
  •  情话喂你
    2020-11-22 14:57

    NoSuchElementException will be thrown if no more tokens are available. This is caused by invoking nextInt() without checking if there's any integer available. To prevent it from happening, you may consider using hasNextInt() to check if any more tokens are available.

提交回复
热议问题