What results do you get for the input you show?

Try debugging your code by adding printlns to show the logic flow and how variable values change.
Be sure to add id Strings to the prints to be...