import [Link].
Scanner; // Import Scanner class to read user input
public class QuizGame {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
// Initialize questions, options, and answers
String[] questions = {
"1. What is the capital of France?",
"2. Which planet is known as the Red Planet?",
"3. Who wrote 'Romeo and Juliet'?",
"4. What is the largest ocean on Earth?",
"5. What is the chemical symbol for water?"
};
String[][] options = {
{"A. London", "B. Berlin", "C. Paris", "D. Madrid"},
{"A. Venus", "B. Mars", "C. Jupiter", "D. Saturn"},
{"A. Charles Dickens", "B. William Shakespeare", "C. Mark Twain", "D. Jane Austen"},
{"A. Atlantic Ocean", "B. Indian Ocean", "C. Arctic Ocean", "D. Pacific Ocean"},
{"A. O2", "B. H2O", "C. CO2", "D. NaCl"}
};
char[] answers = {'C', 'B', 'B', 'D', 'B'}; // Correct answers
int score = 0; // To track number of correct answers
// Loop through each question
for (int i = 0; i < [Link]; i++) {
[Link](questions[i]);
for (String option : options[i]) {
[Link](option);
}
[Link]("Enter your answer (A, B, C, D): ");
String input = [Link]().trim().toUpperCase();
// Input validation
while ( &&  &&  && !
[Link]("D")) {
[Link]("Invalid input. Please enter A, B, C, or D: ");
input = [Link]().trim().toUpperCase();
}
// Compare user's answer with the correct answer
switch (input) {
case "A":
if (answers[i] == 'A') score++;
break;
case "B":
if (answers[i] == 'B') score++;
break;
case "C":
if (answers[i] == 'C') score++;
break;
case "D":
if (answers[i] == 'D') score++;
break;
}
[Link](); // Print a blank line for readability
}
// Calculate and display final score
double percentage = ((double) score / [Link]) * 100;
[Link]("Quiz Completed!");
[Link]("You got " + score + " out of " + [Link] + " correct.");
[Link]("Your final score: %.2f%%\n", percentage);
[Link]();
}
}
Screenshot for output