File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments