Hi, I am working on a program that prompts the user for answers to a quiz. The answers can only be a, b, c or d and they are saved to an array which I later compare to my answer key array. Below is the method I have written to get the user input and validate it but I can't seem to get the validate correct. The way it's written now it always tells me that the input is invalid but then save it and continue on to the next answer prompt. If I enter something other than a, b ,c ,or d it will terminate....where I am I going wrong? Should I be validating at the String for user input or am I validating/comparing the user answers in the wrong manner? Any help is appreciated. Thank you!
public static char[] getAnswers(char arrayAnswers[ ])
{
String userInput;
for (int index = 0; index < arrayAnswers.length; index++)
{
userInput= JOptionPane.showInputDialog("Enter the answer to question " + (index +1) + ":");
arrayAnswers[index] = userInput.charAt(0);
while (arrayAnswers[index]!=('a') && (arrayAnswers[index]!=('b')&& arrayAnswers[index]!=('c')&&(arrayAnswers[index]!=('d'))));
{
JOptionPane.showMessageDialog(null, "Please enter a valid answer");
userInput= JOptionPane.showInputDialog("Enter the answer to question " + (index +1) + ":");
}
}
return arrayAnswers;
}