Array access safe read
Java
Easy
5 views
Problem Description
Task: return a[index] if valid else throw IndexOutOfBoundsException.
Output Format
Return value
Constraints
Check bounds manually.
Official Solution
static int readAt(int[] a,int idx){if(idx<0||idx>=a.length) throw new IndexOutOfBoundsException();return a[idx];}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!