← 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
Topics:
Miscellaneous
Code Editor
1
Tab to indent · Ctrl+Enter to run · 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.