Problem:
The problem is to write a program that grades multiple-choice tests. Suppose there are eight students and ten questions, and the answers are stored in a two-dimensional array. Each row records a student’s answers to the questions, as shown in the following array.
The key is stored in a one-dimensional array:
Key to the Questions: 0 1 2 3 4 5 6 7 8 9
D B D C C D A E A D
Your program grades the test and displays the result. It compares each student’s answers with
the key, counts the number of correct answers, and displays it.
Output:

Solution:
import java.util.Scanner; public class twoDimentionalArrays { public static void main (String[] args) { Scanner scan = new Scanner (System.in); String[] answers = { "D","B","D","C","C","D","A","E","A","D"}; String[][] list = new String[8][10]; System.out.println("Fill in the eight student's answers to 10 questions" ); for (int i =0;i<list.length;i++) { int count =0; for (int j=0;j<list[i].length;j++) { list[i][j] = scan.next(); if(list[i][j].equalsIgnoreCase(answers[j])) count++; } System.out.println("Student's " + i + " correct answers are " + count); } } }
Hello,
ReplyDeleteI was wondering if you could direct me to the library you used for this.
Hello! No external libraries were used for this program. The library used in this program is found by default in Java. It is called the "Scanner" library. You can import it in any Java program without having to add any dependencies.
DeleteInformation about the library can be found here: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
--
George
Can i get this code in c language?
ReplyDeleteJava
Delete