← Back to Miscellaneous
Question 217
Multi-Catch with | Operator
Multi-Catch with | Operator
Write a program that reads a string from input. Try to parse it as an integer usingInteger.parseInt(), then printarr[parsedValue]from the array{10, 20, 30}. Use a singlecatchblock with the|operator to catch bothNumberFormatExceptionandArrayIndexOutOfBoundsException. Print"Error caught"when either occurs. If both operations succeed, print the array element. ⚠️ AUTO-INPUT MODE: The input stream will automatically contain'abc\n'.
Expected Output:
Error caught= 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.