Count Valid Integers in a Loop
mediumQuestion 225Read 5 lines of input. For each line, try to parse it as an integer. Count how many lines are valid integers and how many are invalid. At the end, print:
Valid: X
Invalid: Y
Use a loop with a try-catch inside.
⚠️ AUTO-INPUT MODE: The input stream will automatically contain '10\nabc\n3\nhello\n7\n'.
Expected output
Valid: 3 Invalid: 2
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Miscellaneous
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.