Problem 48 in Java