(java) Solved problem 10