← Back to Miscellaneous
Question 225
Count Valid Integers in a Loop
Count Valid Integers in a Loop
Read 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: XInvalid: YUse a loop with atry-catchinside. ⚠️ 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 — 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.