We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,415 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Checking out of bound exception

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
7 Hours
Discussion Span
7 Months Ago
Last Updated
6
Views
RozenKristal
Newbie Poster
13 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Got this part working :)

RozenKristal
Newbie Poster
13 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

an array, I need to check when it is out of bound

The valid indexes for an array range from 0 to the length of the array-1.
See this page in the tutorial: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

can you explain what you did to make it work?

jamesmadison43
Newbie Poster
11 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

thanks

jamesmadison43
Newbie Poster
11 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0762 seconds using 2.73MB