(java) Solved problem 52