Answer: He bought 4 pastries.
Explanation:
Let x = Number of cups of coffee
y= Number of pastries.
As per given,
x+y=9 ....(i)
2.5x+4y=28.50 ...(ii)
Multiply 4 to (i), we get
4x+4y=36 ...(iii)
Eliminate (ii) from (iii), we get

Put x=5 in (i) , we get
5+y=9
y= 4
Hence, He bought 4 pastries.