Stuck at “Exception in thread ”main" java.util.NoSuchElementException

后端 未结 2 1879
有刺的猬
有刺的猬 2021-01-25 04:45

I wrote a program with a separate class but I keep getting the same error right after the user inputs the three sides.

The main code is:

package interac         


        
2条回答
  •  不要未来只要你来
    2021-01-25 04:57

    Try removing the following line:

    console.close();
    

    You can't read from console once you've closed it.

    You almost certainly shouldn't explicitly close your Scanner: doing so will close System.in. It is not a good practice to close a stream that you haven't opened yourself, since some other code may rely on the stream being open, and throw an exception when it isn't.

    Debugging such a problem - where the exception is potentially thrown a long way from the cause - is very tricky.

提交回复
热议问题