Can you show what you input to the program and what it prints out?
How often is (sum == c)?
Add a println to print out the value of c and the value of sum so you will see what the program is doing...