← Back to Exceptions
Question 669
Handle Invalid Number Format
Handle Invalid Number Format
Read one line of input and parse it to anintwithint.Parse, then printNumber: <n>. If the text is not a valid integer,int.Parsethrows aFormatException— catch it and print exactlyNot a number. Use top-level statements withtry/catch. Input42prints: Number: 42 Inputabcprints: Not a number
Expected Output:
Number: 42
Topics:
Exceptions
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.