Problem 34 in Java