(java) Solved problem 27