CJCoding With Joseph

Array Index Out Of Range

An array arr = { 10, 20, 30 } is given. Read an index from input and print arr[index]. If the index is out of bounds, catch the IndexOutOfRangeException and print Error: index out of range. Use top-level statements with try/catch.

Input 1 prints: 20
Input 5 prints: Error: index out of range

Expected Output:

20
Topics:
Exceptions
๐Ÿ“ฅ Auto-Input:
1\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 (cw, cr, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.