(java) Solved problem 45