Solved Problem7 in java (update)