Repository navigation
Expand file tree
/
Copy pathLesson36_quizGame.java
More file actions
49 lines (37 loc) · 1.79 KB
/
Copy pathLesson36_quizGame.java
File metadata and controls
49 lines (37 loc) · 1.79 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 Lesson36_quizGame {
public static void main(String[] args) {
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 computer?",
"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 score = 0;
int guess;
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the Java Quiz Game!");
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 = Integer.parseInt(sc.nextLine());
if(guess == answers[i]) {
System.out.println("Correct!");
score++;
}
else {
System.out.println("Wrong! The correct answer is: " + answers[i]);
}
}
System.out.println("Your final score is: " + score + " out of " + questions.length);
sc.close();
}
}