• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why ArrayIndexOutOfBounds exception?  RSS feed

 
manu lix
Ranch Hand
Posts: 74
Java MySQL Database Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have an problem I can not resolve!

There are 3 array of Strings.
1. array unit contains the units(i.g. "one", "two", "three"...and finally.. "nineteen").
2. array tens contains the tens(i.g. "ten", "eleven"...
3. array hundreds contains the hundreds(i.g."hundred", "two handred", and finally "nine hundred").

Aim of application: convert the input number and return string, i.g. enter 321 -> output: three hundred and twenty.
For the number range 1 - 120 it's ok But, 120 up no, so getting ArrayIndexOutOfBounds.
For the number range < 20 i have an method, while for all the others I thought all in one method.
Now, the problem seems to be the concatenation of strings.

This is the problematic snippet code :


I hope to have been pretty clear for help
 
Stephan van Hulst
Saloon Keeper
Posts: 7969
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayIndexOutOfBounds usually means you're trying to get an element from an array using an index that's too big.

For n = 121, what is the value of tens[n/10] ?
 
manu lix
Ranch Hand
Posts: 74
Java MySQL Database Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:ArrayIndexOutOfBounds usually means you're trying to get an element from an array using an index that's too big.

For n = 121, what is the value of tens[n/10] ?


"twenty".

Edit: bug tens[n%10] instead of tens[n/10]... But print the string wrong: one hundred and ten
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!