(java) Solved problem 36