Project Euler #31 Solution (Java)