Solution to Project Euler problem 1 in Java