Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Keep taking numbers as inputs till the user enters ‘x’, after that print sum of all.

What I have tried:

Please help, I know how to stop that program using an integer but using an String to stop it is not getting into my mind.
Updated 3-Jul-23 8:12am

1 solution

If you use the Scanner.hasNextInt() (Java Platform SE 7 )[^] method, you will get feedback as to whether there is an integer or something else in the input buffer.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900