solving second problem in java