(java) Solved problem 38