(java) Solved problem 37