-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleQuiz.java
More file actions
49 lines (40 loc) · 1.88 KB
/
SimpleQuiz.java
File metadata and controls
49 lines (40 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
public class SimpleQuiz {
public static void main(String[] args) {
// Simple Quiz game
String[] questions = {"What is the main function of a router?",
"Which part of the computer is considered the brain?",
"What year was Facebook launched?",
"Who is known as the father of computers?",
"What was the first programming language?"};
String[][] options = {{"1. Storing files", "2. Encrypting data", "3. Directing internet traffic", "4. Managing passwords"},
{"1. CPU", "2. Hard Drive", "3. RAM", "4. GPU"},
{"1. 2000", "2. 2004", "3. 2006", "4. 2008"},
{"1. Steve Jobs", "2. Bill Gates", "3. Alan Turing", "4. Charles Babbage"},
{"1. COBOL", "2. C", "3. Fortran", "4. Assembly"}};
int[] answers = {3, 1, 2, 4, 3};
int guess;
int score= 0;
Scanner scanner = new Scanner(System.in);
System.out.println("*********************");
System.out.println("Welcome to the Quiz!");
System.out.println("*********************");
for(int i = 0; i < questions.length; i++) {
System.out.println(questions[i]);
for(String option : options[i]) {
System.out.println(option);
}
System.out.print("Enter your guess: ");
guess = scanner.nextInt();
if(guess == answers[i]) {
System.out.println("CORRECT!");
score++;
} else {
System.out.println("WRONG!");
}
}
System.out.println("Your final score is " + score + " out of " + questions.length);
// Display final score
scanner.close();
}
}