Project Euler, Problem 40, Java