(java) Solved problem 17