JVM Project
JVM Project
Scanner;
// Quiz loop
for (int i = 0; i < quizData.length; i++) {
String[] question = quizData[i];
System.out.println("\nQuestion " + (i + 1) + ": " + question[0]);
System.out.println("Options:");
for (int j = 1; j < question.length - 1; j++) {
System.out.println(question[j]);
}
// User input
System.out.print("Your answer (A/B/C/D): ");
String userChoice = scanner.nextLine();
// Check answer
if (userChoice.equalsIgnoreCase(question[5])) {
System.out.println("Correct!");
score++;
} else {
System.out.println("Incorrect. The correct answer is: " + question[5]);
}
}
scanner.close();
}
}