(java) Solved problem 50