← 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
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.