← Back to Miscellaneous
Question 222
Nested Try-Catch
Nested Try-Catch
Write a program that reads a string. Use nested try-catch blocks: - The **outer** try-catch parses the string as an integer. If it fails, catchNumberFormatExceptionand print"Outer: not a number". - Inside the outer try, the **inner** try-catch accessesarr[index]wherearr = {5, 10, 15}. If that fails, catchArrayIndexOutOfBoundsExceptionand print"Inner: index out of bounds". - If both succeed, print the element. ⚠️ AUTO-INPUT MODE: The input stream will automatically contain'1\n'.
Expected Output:
10
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.