(java) Solved problem 46