Final answer:
The man in the front knew his hat color based on the responses of the men behind him. Through logical reasoning, he deduced that he must be wearing a black hat.
Step-by-step explanation:
The man in the front knew the color of his hat because of the responses from the men behind him. Let's break it down step by step:
The man in the rear cannot see anyone's hat and says, 'I don't know.' This implies that there are at least two black hats behind him. If there were two white hats, he would know his own hat color, but since he doesn't, there must be at least one black hat.
The man in the middle, who can see the hat of the man in front, also says, 'I don't know.' This means that the man in front is not wearing a white hat, otherwise the man in the middle would see a white hat and know he is wearing a black hat.
Based on the previous two responses, the man in front deduces that he must be wearing a black hat. If he was wearing a white hat, both the man in the rear and the man in the middle would know their own hat colors. Therefore, the front man confidently says, 'I know!'. His hat color is black.