-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathQuiz.java
More file actions
65 lines (56 loc) · 1.56 KB
/
Quiz.java
File metadata and controls
65 lines (56 loc) · 1.56 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
//Quiz
import java.io.*;
import java.util.Scanner;
public class Quiz
{
public static void main(String args[])throws IOException
{
int i=0;
String s="",s1="";
int score=0;
char ch,ch1;
Scanner sc=new Scanner(System.in);
FileReader f= new FileReader("./Question.txt");//file object for question file(change the file location where the file is saved)
BufferedReader bf=new BufferedReader(f);
FileReader f1= new FileReader("./Answer.txt");// file object for answer file(change the file location where the file is saved)
BufferedReader bf1=new BufferedReader(f1);
while(true)
{
s=bf.readLine();//reading the question
if (s==null)
break;
System.out.println(s);
s=bf.readLine();//reading option a from question file
System.out.println(s);
if (s==null)
break;
s=bf.readLine();//reading option b from question file
System.out.println(s);
if (s==null)
break;
s=bf.readLine();//reading option c from question file
System.out.println(s);
if (s==null)
break;
s=bf.readLine();//reading option d from question file
System.out.println(s);
if (s==null)
break;
System.out.println("Enter the correct option (a,b,c,d)");//taking answer as input
ch=sc.next().charAt(0);
s1=bf1.readLine();//reading the answer from the answer file
ch1=s1.charAt(0);
if(ch==ch1)//comparing the input answer with the correct answer
{
System.out.println("correct answer");
score++;
}
else
{
System.out.println("wrong answer");
break;
}
}
System.out.println("Your score is "+score);//displaying the score
}
}