Refer to the table below. The colum labeled "M" is the midpoint for each age interval. To find the midpoint, add up the endpoints and divide by 2. For example, the midpoint of 18 and 24 is (18+24)/2 = 42/2 = 21. Notice how the values of M are increasing by 7 each time.
The column labeled fM refers to multiplying the frequency f with the midpoint M. Example: fM = 6*21 = 126 in the first row.
Add up everything in the column labeled fM and you should get 1484. Divide this over the sum of the frequencies (40) and the mean is 1484/40 = 37.1