For my assignment we've been asked to add in a manual IndexOutOfBoundsException.
public int get(Object[] objArr){
size = objArr.length;
for(int i = 0; i < size; i++ )
if(objArr[i] < 0 || objArr[i] > objArr.length )
{
throw new IndexOutOfBoundsException("I must be greater than 0 and less than " + size);
}
I'm trying to get the code to loop through the look and check for numbers less than 0 and their index is outside of the array declared by the user. I'm getting an error for my if statement, and was wondering on how I could fix that.
Object
andint
?!i
index in an array withobjAr[i]
which is the value in that array.