Euler Problem 7 in Java