โ Back to Exceptions
Question 646
Array Index Out Of Range
Array Index Out Of Range
An arrayarr = { 10, 20, 30 }is given. Read an index from input and printarr[index]. If the index is out of bounds, catch theIndexOutOfRangeExceptionand printError: index out of range. Use top-level statements withtry/catch. Input1prints: 20 Input5prints: Error: index out of range
Expected Output:
20
Topics:
Exceptions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.