(java) Solved problem 29