Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

CODE:

import java.util.Scanner;

public class MultipleChoiceQuiz {

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
int score = 0; // Initialize score

// Array to store questions and their correct answers


String[][] questions = {
{"The computer presents output on which device?", "A. Keyboard", "B. Mouse", "C.
Moniter", "D. Headphones", "C"},
{"Which component of computer saves the data permenantely?", "A. RAM", "B. ROM", "C.
HDD", "D. Processor", "C"},
{"What is the full form of GPU?", "A. Graphics Processing Unit", "B. Graphics Packaging
Unit", "C. Game Processing Unit", "D. Graphics Packaging Ultra", "A"},
{"Which one of these is a input device", "A. Monitor", "B. Printer", "C. RAM", "D. Mouse",
"D"},
{"Who painted the Mona Lisa?", "A. Leonardo da Vinci", "B. Pablo Picasso", "C. Vincent van
Gogh", "D. Michelangelo", "A"}
};

// Display questions, get user answers, and track score


for (int i = 0; i < questions.length; i++) {
String[] question = questions[i];
System.out.println(question[0]);
for (int j = 1; j < question.length - 1; j++) {
System.out.println(question[j]);
}
System.out.print("Your answer (A, B, C, or D): ");
String userAnswer = scanner.nextLine().toUpperCase(); // Convert input to uppercase for case-
insensitivity

// Check user's answer against correct answer


if (userAnswer.equals(question[question.length - 1])) {
score++; // Increment score if answer is correct
} else {
System.out.println("Incorrect. Correct answer: " + question[question.length - 1]);
}
System.out.println();
}

// Calculate and display final score


double percentageScore = (double) score / questions.length * 100;
System.out.println("Your final score: " + percentageScore + "%");
}
}

OUTPUT:

You might also like