Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Grades {
- public static void main(String args[]) {
- Scanner input = new Scanner(System.in);
- char[][] answers = {
- {'A', 'B', 'A', 'C', 'C', 'D' },
- {'D', 'B', 'A', 'B', 'C', 'A' },
- {'D', 'B', 'D', 'A', 'C', 'D' },
- {'C', 'B', 'A', 'E', 'D', 'C' }};
- char[] keys = {'D', 'B', 'D', 'C', 'C','D'};
- //******* Complete the code to count the number of correct answers for each
- //******* student and print them.
- for(int i=0;i<=answers.length-1;i++){
- int c = 0;
- for(int j=0;j<=answers[i].length-1;j++){
- if(answers[i][j]==keys[j]) c++;
- }
- System.out.printf("Student %d grade :%d%n",i,c);
- }
- int student, ans;
- System.out.print("Enter the student and question number: ");
- student = input.nextInt();
- ans = input.nextInt();
- //******* Complete the code to print the student’s answer for the given
- //******* question, and print whether it is correct or incorrect.
- if(answers[student][ans]==keys[ans])
- System.out.printf("The student answer was %s it is correct.",answers[student][ans]);
- else
- System.out.printf("The student answer was %s it is incorrect.",answers[student][ans]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement