Hello,
I am having a bit of trouble validating single Chars inputted by the user for my intro to java class. I usually validate it with a while loop when its numbers (double, int, etc) but i cant seem to find a right way to validate these.
the program is to ask the user to answer to a test of 20 questions ( A,B,C or D) and then store it in an array.This is what i have so far (minus the rest of the code). no syntax errors given by netbeans =/
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter Your Answers for the Exam "
+ "(CAPS LOCK ON!)");
for (int index = 0; index < 19; index++)
{
System.out.println("Enter Answer for Question #" + (index + 1)
+ ":");
givenAnswers[index] = keyboard.next().charAt(0);
while (givenAnswers[index] != 'A' || givenAnswers[index] != 'B' ||
givenAnswers[index] != 'B'|| givenAnswers[index] != 'C')
{
System.out.println("Please Enter a Valid Answer (A,B,C, or D)");
givenAnswers[index] = keyboard.next().charAt(0);
}
}
this is what i get in the run window(its like its not validating at all??? and just keeps going) :
run:
Enter Your Answers for the Exam (CAPS LOCK ON!)
Enter Answer for Question #1:
A
Please Enter a Valid Answer (A,B,C, or D)
B
Please Enter a Valid Answer (A,B,C, or D)
C
Please Enter a Valid Answer (A,B,C, or D)
D
Please Enter a Valid Answer (A,B,C, or D)
any thoughts?? thanks in advanced