problem 21 in Java