For debugging your code I'd recommend you add printlns to show the values of variables as they change and to show the execution flow. The print out should help you understand what the problem is.
You forgot to show what the correct output should be.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656