Results 1 to 4 of 4
Thread: ArrayIndexOutOfBoundsException
- 01-26-2011, 09:34 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 5
- Rep Power
- 0
ArrayIndexOutOfBoundsException
Not sure why I'm getting this error. I'm trying to create arrays that gradually go up in size (start at 1,000 and increase by 1,000 each time until the last array created is 50,000) and fill them with random numbers between 1-1,000,000. Please help!Java Code:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1000 at SortersTester.main(SortersTester.java:10)
Java Code:import java.util.Random; public class SortersTester { public static void main (String[] args){ Random r = new Random(); for (int size=1000; size<=50000; size += 1000) { int [] anArray = new int[size]; for (int i=0; i<=size; i++) { int randint = r.nextInt(1000000); anArray[i] = randint; } } } }
- 01-26-2011, 09:56 PM #2
Hint: If an array has a size of 10, what will its last index be? Draw it out on paper.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-26-2011, 10:12 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 5
- Rep Power
- 0
Ah. So this:
Should be this:Java Code:for (int i=0; i<=size; i++) {
Correct? If so, thank you very much!Java Code:for (int i=0; i<size; i++) {
- 01-26-2011, 10:28 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
ArrayIndexOutOfBoundsException: 10 ??
By Yakg in forum New To JavaReplies: 2Last Post: 12-04-2010, 06:56 PM -
ArrayIndexOutOfBoundsException
By er1c550n20 in forum New To JavaReplies: 2Last Post: 04-07-2010, 06:50 PM -
ArrayIndexOutOfBoundsException
By Corey in forum New To JavaReplies: 5Last Post: 02-02-2010, 01:25 AM -
ArrayIndexOutofBoundsException help
By filly444 in forum New To JavaReplies: 9Last Post: 09-03-2008, 05:16 PM -
ArrayIndexOutOfBoundsException
By daredavil82 in forum New To JavaReplies: 2Last Post: 12-14-2007, 09:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks