Project Euler, Problem 31, Java