Array Index Out Of Range
easyQuestion 736An 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, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
Exceptions
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.