Skip to content

Commit cfec246

Browse files
authored
Create QuizApp.java
1 parent 8528255 commit cfec246

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

QuizApp.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.util.Scanner;
2+
3+
public class QuizApp {
4+
public static void main(String[] args) {
5+
// Define some sample questions and answers
6+
String[] questions = {
7+
"What is the capital of France?",
8+
"What is the largest planet in our solar system?",
9+
"Who wrote Romeo and Juliet?"
10+
};
11+
12+
String[] answers = {
13+
"Paris",
14+
"Jupiter",
15+
"William Shakespeare"
16+
};
17+
18+
// Initialize the quiz
19+
int score = 0;
20+
Scanner scanner = new Scanner(System.in);
21+
22+
// Iterate through the questions
23+
for (int i = 0; i < questions.length; i++) {
24+
System.out.println(questions[i]);
25+
String userAnswer = scanner.nextLine();
26+
27+
if (userAnswer.equalsIgnoreCase(answers[i])) {
28+
System.out.println("Correct!\n");
29+
score++;
30+
} else {
31+
System.out.println("Incorrect. The correct answer is: " + answers[i] + "\n");
32+
}
33+
}
34+
35+
// Display the final score
36+
System.out.println("Quiz complete! Your score is: " + score + " out of " + questions.length);
37+
38+
// Close the scanner
39+
scanner.close();
40+
}
41+
}

0 commit comments

Comments
 (0)