problem 1 solved in java