Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] integerArray = {2, 4, -3};
- //suppose x comes from an unknown source,
- //e.g. user input
- int x = ...
- int y = integerArray[x];
- try{
- y = integerArray[x];
- } catch(ArrayIndexOutOfBoundsException e){
- y = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment