Project Euler, Problem 14 Java