The mean can be calculated by multiplying each value by the number of students for that value, summing those products, and then dividing by the total number of students.
(1 x 8) + (2 x 6) + (3 x 4) + (4 x 2) + (5 x 1) = 8 + 12 + 12 + 8 + 5 = 45
45 / 21 = 2.14
Therefore, the mean number of hours students spent on math homework is 2.14 hours.