So I made a program, which loops 2 questions from an array. What I want to happen here is to prompt if the user entered blank or empty, and also if the user inputs any other letter, number or symbol aside from a, b, and c. What's happening here is whenever I input a on the first question it also prints "That answer can't be blank" which it shouldn't since I entered a valid input.
do{
System.out.print(question[i].prompt + "\nAnswer: ");
answer = s.nextLine();
if(
!answer.equalsIgnoreCase("a") &&
!answer.equalsIgnoreCase("b") &&
!answer.equalsIgnoreCase("c")
){
System.out.println("Invalid input!\n");
}
if(!answer.isEmpty()){
System.out.println("The answer can't be blank.\n");
}
}
while(
!answer.equalsIgnoreCase("a") &&
!answer.equalsIgnoreCase("b") &&
!answer.equalsIgnoreCase("c") &&
!answer.isEmpty()
);
if(answer.equalsIgnoreCase(question[i].answer)){
score++;
}
}```
Aucun commentaire:
Enregistrer un commentaire