(java) Solved problem 24