Jeremy Parsons,
The following is the code and tested and it works fine, here you need to understand that after reading the input(
you should not support to read 3 times as you done in your program) you should clean the buffer for that I am using 2 dummy read statements(any one is there any better way?).
import java.io.IOException;
public class MathTest
{
public static void main(
String[]args) throws Exception
{
int a1,a2,a3,a4,a5;
int userInput;
// Question #1
System.out.println("1. 7 + 2 = ? a.6 b.8 c.9 d.10");
System.out.print("Enter your answer: ");
a1 = System.in.read();
userInput=System.in.read();
userInput=System.in.read();
if (a1 == 'c')
{
System.out.println("Correct!");
System.out.println();
}
else
{
System.out.println("Sorry! The correct answer is c");
System.out.println();
}
//Question #2
System.out.println("2. 9 - 5 = ? a.2 b.4 c.6 d.8");
System.out.print("Enter your answer: ");
a2 = System.in.read();
userInput=System.in.read();
userInput=System.in.read();
if (a2 == 'b')
{
System.out.println("Correct!");
System.out.println();
}
else
{System.out.println("Sorry! The correct answer is b");
System.out.println();
}
//Question #3
System.out.println("3. 144/12 = ? a.10 b.12 c.14 d.16");
System.out.print("Enter your answer: ");
a3 = System.in.read();
userInput=System.in.read();
userInput=System.in.read();
if (a3 == 'b')
{
System.out.println("Correct!");
System.out.println();
}
else
{System.out.println("Sorry! The correct answer is b");
System.out.println();
}
//Question #4
System.out.println("4. 5 * 5 = ? a.10 b.20 c.25 d.125");
System.out.print("Enter your answer: ");
a4 = System.in.read();
userInput=System.in.read();
userInput=System.in.read();
if (a4 == 'c')
{
System.out.println("Correct!");
System.out.println();
}
else
{System.out.println("Sorry! The correct answer is c");
System.out.println();
}
//Question #5
System.out.println("5. 2 + 3 + 5 = ? a.7 b.8 c.9 d.10");
System.out.print("Enter your answer: ");
a5 = System.in.read();
userInput=System.in.read();
userInput=System.in.read();
if (a5 == 'd')
{
System.out.println("Correct!");
System.out.println();
}
else
{System.out.println("Sorry! The correct answer is d");
System.out.println();
}
}
}
-Ram.