Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Question about: java.lang.ArrayIndexOutOfBoundsException

843785Nov 11 2008 — edited Nov 11 2008
I keep getting this error.
First call to assembleArray(): 
	Enter the first integer: 
42
	Enter the second integer: 
427

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
	at filename.assembleArray(filename.java:151)
	at filename.main(filename.java:18)
but when I put something like the following it works:
First call to assembleArray(): 
	Enter the first integer: 
1328
	Enter the second integer: 
456
The resulting array has 4 elements as follows,
  [ 0 2 3 0 ]
line 151:
finalArray[ finalIndex ] = finalNum;
line 18:
lastArray = assembleArray (firstA, firstB);
I know it has something to do with the index but I dont know how to fix it because I can't set the index since it depends on user input.
For the resulting array, the first number is the sum of all odd one-digits, second number is the sum of all even 10-digits, and the third number is the sum of all multiples of 3.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 9 2008
Added on Nov 11 2008
20 comments
417 views