CJCoding With Joseph
15per day

Multi-Catch with | Operator

Write 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
Topics:
Miscellaneous
📥 Auto-Input:
abc\n
This input is automatically fed to your program's stdin
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.