CJCoding With Joseph
15free / daySign inCreate account

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

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Exceptions
📥 Auto-Input:
1\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.