Question: How can I fix this program ? I try to fix that if users don't answer A, B, C, or D. How can the program

How can I fix this program ? I try to fix that if users don't answer A, B, C, or D. How can the program remind them ? I try to use if else for that but that is not working.

import java.util.Scanner;

public class DriverLicense

{

public static void main(String[] args)

{

String Answers[] = {"B", "D", "A", "A", "C",

"A", "B", "A", "C", "D",

"B", "C", "D", "A", "D",

"C", "C", "B", "D", "A"};

String userAnswers[] = new String[20];

boolean isCorrect[] = new boolean[20];

int correctAnswers = 0;

int incorrectAnswers = 0;

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter A/B/C/D only as answers:");

for(int i = 0; i < 20; i++)

{

System.out.print("The answer of question " + (i + 1) + ": ");

userAnswers[i] = keyboard.next();

if(userAnswers[i].equalsIgnoreCase(Answers[i]))

{

correctAnswers++;

isCorrect[i] = true;

}

else

{

incorrectAnswers++;

isCorrect[i] = false;

}

}

System.out.println(" Exam Result:");

if(correctAnswers >= 15)

System.out.println("Student is passed in the exam.");

else

System.out.println("Student is not passed in the exam.");

System.out.println("The total number of correctly answered questions: " + correctAnswers);

System.out.println("The total number of incorrectly answered questions: " + incorrectAnswers);

System.out.println("The question numbers of the incorrectly answered questions:");

for(int i = 0; i < isCorrect.length; i++)

{

if(isCorrect[i] == false)

System.out.println(i + 1);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!