To see what the code is doing, try debugging the code by adding lots of println statements to print out the values of the variables as they are used and changed.