x - the number of questions he answered correctly
y - the number of questions he answered incorrectly
There were 40 questions on the test.
[tex]x+y=40 \\ y=40-x[/tex]
The correct answers were given 5 points each, the incorrect answers were given -2 points each. He made a score of 95.
[tex]5x-2y=95 \\
-2y=95-5x \\
y=-\frac{95}{2}+\frac{5}{2}x
[/tex]
Set 40-x and (-95/2)+(5/2)x equal to each other:
[tex]40-x=-\frac{95}{2}+\frac{5}{2}x \\
-x-\frac{5}{2}x=-\frac{95}{2}-40 \\
-\frac{2}{2}x-\frac{5}{2}x=-\frac{95}{2}-\frac{80}{2} \\
-\frac{7}{2}x=-\frac{175}{2} \\
x=-\frac{175}{2} \times (-\frac{2}{7}) \\
x=\frac{175}{7} \\
x=25[/tex]
Johnny answered correctly 25 questions.