-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuizAssignment.java
More file actions
109 lines (83 loc) · 3.18 KB
/
QuizAssignment.java
File metadata and controls
109 lines (83 loc) · 3.18 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package com.quizApplication;
import java.util.*;
public class QuizAssignment {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int score=0;
do {
System.out.println("Welcome to the QUIZ GAME...");
System.out.println("Press 'Y' to Start [Attention: USE CAPSLOCK ON]");
char key = sc.next().charAt(0);
char playAgain;
if(key == 'Y') {
do {
System.out.println("Q1. Which data type is used to store decimal numbers in Java?");
System.out.println("A. int \nB. float \nC. char \nD. boolean");
System.out.print("Answer: ");
char ans1 = sc.next().charAt(0);
if(ans1 == 'B') {
System.out.println("Correct");
score++;
}else {
System.out.println("Oops Incorrect, Better Luck Next Time!");
}
System.out.println();
System.out.println("Q2. Java is known as a platform-independent language because: ");
System.out.println("A. It can only run on Windows \nB. Java programs are compiled into machine code \nC. Java programs are compiled into bytecode that runs on JVM \nD. It requires no compilation");
System.out.print("Answer: ");
char ans2 = sc.next().charAt(0);
if(ans2 == 'C') {
System.out.println("Correct");
score++;
}else {
System.out.println("Oops Incorrect, Better Luck Next Time!");
}
System.out.println();
System.out.println("Q3. Java is a _______ language");
System.out.println("A. Low-level \nB. Middle-level \nC. Machine-level \nD. High-level");
System.out.print("Answer: ");
char ans3 = sc.next().charAt(0);
if(ans3 == 'D') {
System.out.println("Correct");
score++;
}else {
System.out.println("Oops Incorrect, Better Luck Next Time!");
}
System.out.println();
System.out.println("Q4. Which of the following executes Java bytecode?");
System.out.println("A. JDK \nB. JVM \nC. Compiler \nD. JIT");
System.out.print("Answer: ");
char ans4 = sc.next().charAt(0);
if(ans4 == 'B') {
System.out.println("Correct");
score++;
}else {
System.out.println("Oops Incorrect, Better Luck Next Time!");
}
System.out.println();
System.out.println("Q5. Who developed Java?");
System.out.println("A. Sun Microsystems \nB. Microsoft \nC. Google \nD. Apple");
System.out.print("Answer: ");
char ans5 = sc.next().charAt(0);
if(ans5 == 'A') {
System.out.println("Correct");
score++;
}else {
System.out.println("Oops Incorrect, Better Luck Next Time!");
}
System.out.println();
System.out.println("Final Result: " + score + "/5 Quiz are Correct");
System.out.println();
System.out.println("Want to Play Again? (Y/N)");
playAgain = sc.next().charAt(0);
if(playAgain == 'N') {
System.out.println("Thank You for Playing");
break;
}
}while(playAgain == 'Y');
}else {
System.out.println("Thank You, Visit Again!");
}
} while(false);
}
}