zeroeth...Welcome to the Ranch! Hopefully we'll be able to help you. to that point...
First, we have no idea what your 'desired result' is, so it would help if you clarify.
Second, since you know what this DOES do, it would help if you told us. does it compile? Does not start? does it start to run and die? Does is run and give the wrong output? what would that output be?
third,
you should never get this far. NEVER write more than 2-3 lines of code before you compile and
test. Do you know if your input is being processed correctly? Do you know if your loops are running the correct number of times? etc.
fourth...the best way to see what's going on is to stick a ton of System.out.println statements in there to see where it is going.
fifth...this is wrong:
There is something in there that is causing your loop to not do what you think it is...it is running, but it is not doing anything terribly useful.