Repository navigation
Expand file tree
/
Copy pathquiz.java
More file actions
57 lines (55 loc) · 2.14 KB
/
Copy pathquiz.java
File metadata and controls
57 lines (55 loc) · 2.14 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
50
51
52
53
54
55
56
57
import java.util.Scanner;
public class quiz {
public static void main(String[] args) {
//question array[]
//optinos array[][]
//declare variable
//welcome message
//question(loop)
// options
// get guess form user
// check guess
// display final score
String[] questions = {
"What is the main function of a router?",
"Which part of the computer is considered the brain?",
"What year was facebook laucnched?",
"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 ", "4. Displays information"},
{"1. CPU", "2. RAM", "3. Hard Drive", "4. Monitor"},
{"1. 2000", "2. 2004", "3. 2006", "4. 2007"},
{"1. Bill Gates", "2. Alan Turing", "3. Ada Lovelace", "4. Charles BabbageBill Gates"},
{"1. COBOL", "2. Assembly", "3. Fortran", "4. C"}
};
int[] answers = {3,1,2,4,3};
int score = 0;
int guess;
Scanner scanner = new Scanner(System.in);
System.out.println("******************************");
System.out.println("Welcome to the Java Quiz Game!");
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("*********");
System.out.println("CORRECT!");
System.out.println("*********");
score++;
}
else{
System.out.println("*********");
System.out.println("INCORRECT!");
System.out.println("*********");
}
}
System.out.println("Your final score is : "+score);
}
}