(java) Solved problem 30