0

THing is I have an assignment where the object is an array, I need to check when it is out of bound. But I dont understand what this statement means? Can you guys help me verify it?

method "private void rangeCheck(int index)": if the value of index is less than 0 or greater than or equal to the size of the dynamic array, then throw new exception IndexOutOfBoundsException("Index: " + index + ", Size: " + size);

at the part if the value of index is less than 0 or greater than or equal to size of dynamic array. So he doesnt mean the index, but the value inside that index, right?

4
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by jamesmadison43
0

can you explain what you did to make it work?

Please read NormR1 link. The index range of an array can be from 0 up to n-1 where n is the size of the array. For example, array size 5 is declared as int[] arr = new int[5]; will have valid indices of 0 up to 4. The range is supposed to check for the incoming index value. The index will be out or range if the value is less than 0 or equal to or greater than the size of the index.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.