(java) Solved problem 35