(java) Solved problem 42