algorithm assignment in java