- Java Programs - Advanced
- Java Programs - Home
- Pernicious Number Program
- Check Matrix Column Sum Program
- Flipgram (Heterogram) Program
- Circular Queue Program
- Flight Passenger Inheritance Program
- Goldbach Number Program
- Shift Matrix Rows Up Program
- Pangram String Program
- Later Date Program
- Symmetric Matrix Program
- Cell Phone Keypad Program
- Unique Digit Integer Program
- Max & Min Elements in Matrix Program
- Anagram Strings Program
- Mask String Program Specimen
- Mix Array Program Specimen
- LCM using Recursion Program Specimen
- Recycle Dequeue Program Specimen
- Library Compute Inheritance Program Specimen
- Linked List & Binary Tree Question Specimen
- Decimal to Hexadecimal Program
- Insertion Sort Program
- Lowest & Highest ASCII Value Program
- Card Game Stack Program
- Employee Salary Overtime Inheritance Program
- Binary Tree 2024 Questions
- Hamming Number Program
- Doubly Markov Matrix Program
- Snowball String Program
- Future Date Program
- Lucky Number Program
- Bar Graph of Vowels & Consonants Program
- Vampire Number Program
- Rotate Matrix by 270 Degree Anticlockwise Program
- Keyword Cipher Program
- Increasing, Decreasing & Bouncy Number Program
- Fill Matrix with Characters Program
- Decode Encoded Text Program
- Project Submission Date Program
- Sort Matrix Boundary Elements Program
- Insert Word in a Sentence Program
- Composite Magic Number Program
- Mirror Image of a Matrix Program
- Common Words in a Paragraph Program
- Dudeney Number Recursive Program
- Matrix Transpose Program
- Sort Words Alphabetically Program
- DeQueue Data Structure Program
- Demand Supply Inheritance Program
- Linked List & Binary Tree Question
- Pronic Number in Java using Recursion
- Unique Word Program
- No Repeated Alphabets Program
- Calculate Series Program
- Reverse Number using Recursion Program
- Item Taxable Inheritance Program
- Stack Data Structure Program
- Evil Number Program
- Merge Two Arrays Program
- Remove Repeated Alphabets Program
- Rack Stack Data Structure Program
- Stock Sales Inheritance Program
- Date and Month Program
- Binary Search using Recursion Program
- Mix Two Words Program
- Circular Queue Program
- Data Interface Program
- Prime Adam Number Program
- Octal to Decimal Conversion Program
- Arrange Words Length-wise Program
- Armstrong Number Program
- Reverse Matrix Elements Program
- Rearrange Vowels & Consonants Program
- Record & Highest Inheritance Program
- Diary Class Queue Program
- Linked List and Binary Tree Program
- Generate Date Program
- Array Format Program
- Generate Palindrome Words
- Perfect Number Program on Recursion
- Checking for Equal Matrices
- Words Beginning with Capital Letter
- Number Series Inheritance Program
- Register Stack Program
- Goldbach Number Program
- Sorting Two-Dimensional Matrix Program
- Vertical Banner Program
- Palindrome using Recursion Program
- Adder Program
- Swap Sort Program
- Product Sales Inheritance Program
- Queue Program on Array
- Cartons Program
- Quiz Program
- Caesar Cipher Program
- Disarium Number Recursive Program
- Shift Matrix Shuffle Program
- ConsChange Program
- Bank Account Inheritance Program
- Bookshelf Stack Program
- Circular Prime Program
- Sort Non-boundary Matrix Elements Program
- Words Beginning and Ending with Vowels Program
- Admission Recursive Binary Search Program
- Merger Class Concatenation Program
- String Frequency Program
- WordPile Stack Program
- Plane Circle Inheritance Program
- Smallest Integer Program
- Rotate Matrix 90 Degrees Program
- Vowels and Consonants Per Word Program
- Merging Sorted Arrays Program
- Series Sum Program
- Fibonacci Strings Program
- Stock Purchase Inheritance Program
- Array to Stack Program
- Composite Magic Program
- Symmetric Matrix Program
- Deleting Word from String Program
- Emirp Number Program
- Exchange Alphabets Program
- Matrix Difference Program
- Perimeter Area Inheritance Program
- Dequeue Queue Program
- ISBN Code Program
- Mirror Image Matrix Program
- Palindrome Words Program
- Combine Array Program
- Vowel Word Program
- Happy Number Program
- Link Queue Program
- Detail Bill Inheritance Program
- Prime Palindrome Program
- Arrange Words Alphabetically Program
- Sort Matrix Elements Program
- Frequency of “And” and “An” Program
- Decimal to Octal Conversion Program
- Pseudo Arithmetic Sequence Program
- Record Rank Inheritance Program
- Stack Program Storing Names
- Number to Words Conversion Program
- Magic Number Program
- Special Number Program
- Triangular Number Program
Java Programs - Advanced
![]() Share with a Friend |
Quiz Program - Java Program
The result of a quiz competition is to be prepared as follows:
The quiz has five questions with four multiple choices (A, B, C, D), with each question carrying 1 mark for the correct answer. Design a program to accept the number of participants N such that N must be greater than 3 and less than 11. Create a double-dimensional array of size (N * 5) to store the answers of each participant row-wise. Calculate the marks for each participant by matching the correct answer stored in a single-dimensional array of size 5. Display the scores for each participant and also the participants(s) having the highest score.
Example: If the value of N = 4, then the array would be:
| Q1 | Q2 | Q3 | Q4 | Q5 | |
| Participant 1 | A | B | B | C | A |
| Participant 2 | D | A | D | C | B |
| Participant 3 | A | A | B | A | C |
| Participant 4 | D | C | C | A | B |
| Key to the question: | D | C | C | A | B |
Note: Array entries are line fed (i.e. one entry per line)
Test your program for the following data and some random data.
Example 1:
INPUT:
N = 5
Participant 1 D A B C C
Participant 2 A A D C B
Participant 3 B A C D B
Participant 4 D A D C B
Participant 5 B C A D D
Key: B C D A A
OUTPUT:
Scores:
Participant 1 = 0
Participant 2 = 1
Participant 3 = 1
Participant 4 = 1
Participant 5 = 2
Highest Score: Participant 5
Example 2:
INPUT:
N = 4
Participant 1 A C C B D
Participant 2 B C A A C
Participant 3 B C B A A
Participant 4 C C D D B
Key: A C D B B
OUTPUT:
Scores:
Participant 1 = 3
Participant 2 = 1
Participant 3 = 1
Participant 4 = 3
Highest score:
Participant 1
Participant 4
Example 3:
INPUT:
N = 12
OUTPUT:
INPUT SIZE OUT OF RANGE.
import java.io.*; class Quiz{ public static void main(String args[]) throws IOException{ InputStreamReader in = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(in); System.out.print("Number of participants: "); int n = Integer.parseInt(br.readLine()); int highest = 0; if(n < 4 || n > 10){ System.out.println("INPUT SIZE OUT OF RANGE."); return; } char q[][] = new char[n][5]; char a[] = new char[5]; int score[] = new int[n]; System.out.println("Key to the questions:"); for(int i = 0; i < a.length; i++) a[i] = br.readLine().charAt(0); System.out.println("Answers by participants:"); for(int i = 0; i < n; i++){ System.out.println("Participant " + (i + 1)); for(int j = 0; j < 5; j++){ q[i][j] = br.readLine().charAt(0); if(q[i][j] == a[j]) score[i]++; } if(highest < score[i]) highest = score[i]; } for(int i = 0; i < n; i++) System.out.println("Participant " + (i + 1) + " = " + score[i]); System.out.println("Highest score(s):"); for(int i = 0; i < n; i++) if(score[i] == highest) System.out.println("Participant " + (i + 1)); } }
Output
OUTPUT : Number of participants: 5 Key to the questions: D C C A B Answers by participants: Participant 1 A B B C A Participant 2 D A D C B Participant 3 A A B A C Participant 4 D C C A B Participant 5 A B C D A Participant 1 = 0 Participant 2 = 2 Participant 3 = 1 Participant 4 = 5 Participant 5 = 1 Highest score(s): Participant 4
