Multi-Catch with | Operator
mediumQuestion 217Write a program that reads a string from input. Try to parse it as an integer using Integer.parseInt(), then print arr[parsedValue] from the array {10, 20, 30}.
Use a single catch block with the | operator to catch both NumberFormatException and ArrayIndexOutOfBoundsException. 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, 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.