Solved problem one in java