(java) Solved problem 49