Solution to Project Euler problem 2 in Java