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?

Recommended Answers

All 5 Replies

Got this part working :)

can you explain what you did to make it work?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.