How to stop reading multiple lines from stdin using Scanner?

后端 未结 4 1899
暗喜
暗喜 2021-02-06 05:28

I\'m working on an JAVA assignment should process multiple lines of input. The instructions read \"Input is read from stdin.\"

An example of sample input is given:

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-06 05:39

    To stop the input, you could either prompt the user to enter quit to exit, and then test for the presence of that String in the input, exiting the loop when found, or you could use a counter in the loop, exiting the loop when the maximum iterations have been reached. The break statement will get you out of the loop.

提交回复
热议问题