-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuizGame.java
More file actions
79 lines (59 loc) · 2.5 KB
/
QuizGame.java
File metadata and controls
79 lines (59 loc) · 2.5 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package LearningWithExercises;
import java.util.Scanner;
public class QuizGame {
public static void main(String [] args){
//java quiz game
//question array[]
//options array[][]
//declare variables
//welcome message
//question message
// question(loop
// options
// get guess from user
//check our guess
//display final score
String []questions={
"What is the main function of a router?",
"Whic part of a computer is considered the brain?",
"What yearwas 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 office traffic","4. Managing passwords"},
{"1. CPU ","2. hardDrive ","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={1,2, 3, 4,3};
int score=0;
int guess;
Scanner scanner=new Scanner(System.in);
System.out.println("******************************************");
System.out.println("Welcome to 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.println("Enter your guess:");
guess=scanner.nextInt();
if (answers[i]==guess){
System.out.println("******************************************");
System.out.println("Correct!");
System.out.println("******************************************");
score++;
}
else {
System.out.println("******************************************");
System.out.println("Wrong");
System.out.println("******************************************");
}
}
System.out.println("Your score is "+score+" out of "+questions.length);
scanner.close();
}
}