-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuizCompetition.java
More file actions
60 lines (58 loc) · 2.1 KB
/
Copy pathQuizCompetition.java
File metadata and controls
60 lines (58 loc) · 2.1 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
package basic;
import java.util.Scanner;
class QuizCompetition {
public static void main(String[] args) {
Scanner ob = new Scanner(System.in);
System.out.println("Enter no of participants");
int N = ob.nextInt();
if (N < 4 || N > 10) {
System.out.println("Invalid Input,no. out of range");
System.exit(0);
}
char Ans[][] = new char[N][5];//Array to store answers of participants
System.out.println("\t Enter answer of each participant row-wise in a single line");
System.out.println("\t\tQ.1 Q.2 Q.3 Q.4 Q.5");
for (int i = 0; i < N; i++)//Loop to enter answers of participants.
{
System.out.print("Participant " + (i + 1) + " : ");
for (int j = 0; j < 5; j++) {
Ans[i][j] = ob.next().charAt(0);
}
}
System.out.println("");
char AnsKey[] = new char[5];//Array to store answer key
System.out.print("Key to the questions :");
for (int i = 0; i < 5; i++)//Loop to enter answer key.
{
AnsKey[i] = ob.next().charAt(0);
}
int A[] = new int[N];//Array to store scores of participants
int temp = 0;
for (int i = 0; i < N; i++)//Loop to calculate score of participants.
{
for (int j = 0; j < 5; j++) {
if (Ans[i][j] == AnsKey[j]) {
A[temp] = A[temp] + 1;
}
}
temp++;
}
System.out.println("");
System.out.println("-Scores of participants-");
System.out.println("");
for (int i = 0; i < N; i++) {
System.out.println("Participant:" + (i + 1) + "=" + A[i]);
}
System.out.println("");
int max = -1, x = 0;
for (int i = 0; i < N; i++)//Loop to calculate the highest scores & scorer
{
if (A[i] > max) {
max = A[i];
x = i + 1;
}
}
System.out.println("Highest scorer : Participant-" + x);
System.out.println("HIghest score : " + max);
}
}