(java) Solved problem 41