(java) Solved problem 21