• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why ArrayIndexOutOfBounds exception?

 
Ranch Hand
Posts: 74
MySQL Database Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic