Let the number of females = x. This means the number of males in the class is x+15.
Put the two together to get x + (x+15) = 31. Simplify to 2x + 15 = 31. Subtract 15 on both sides to get 2x = 16. Divide by 2 on both sides to isolate the x to get x = 8.
There are 8 females in the class meaning there are 23 males in the class.