Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Evaluation of array positions

 
Herbert Morriss
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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].
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Joyce, I should have caught that one...

Have a nice day..

herb
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic