• 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

Evaluation of array positions

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting strang results when I use an expression to calculate the array position.

System.out.println( numbersTeens[numberIn % 10] ) ; Works Fine

but

System.out.println( numbersTens[( ( numberIn/100 ) % 10)]

always evaluates to numbersTens[0].
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what kind of values are you getting for numberIn? if it's anything less that 100, then

numberIn / 100

WILL always be 0, and so the mod 10 will be 0.

are you using numbers > 100?
 
Herbert Morriss
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe a little more code and output would help

[ I removed the code - Pauline ]

here's the output:

numberIn = 69

Sixty-Nine <---- right
Zero-Nine <---- wrong
Press any key to continue . . .

I hope the formatting comes out...




[Sorry to have to do that Herbert, it's just in case anyone working on this one would prefer not to see others' code before they figure it out themselves. -Pauline ]
[ April 12, 2006: Message edited by: Pauline McNamara ]
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Herbert,

Welcome to Cattle Drive!

The two expressions are different. One is ((numberIn / 10) % 10) and the other one is ((numberIn / 100) % 10).

In the second expression, (69 / 100) will result in 0.

Joyce
[ April 10, 2006: Message edited by: Joyce Lee ]
 
Herbert Morriss
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joyce, I should have caught that one...

Have a nice day..

herb
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic