Advertisement
ABaDy1996

labExam2

Nov 25th, 2020
1,656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Grades {
  4.    
  5.     public static void main(String args[]) {
  6.        
  7.         Scanner input = new Scanner(System.in);
  8.        
  9.         char[][] answers = {
  10.             {'A', 'B', 'A', 'C', 'C', 'D' },
  11.             {'D', 'B', 'A', 'B', 'C', 'A' },
  12.             {'D', 'B', 'D', 'A', 'C', 'D' },
  13.             {'C', 'B', 'A', 'E', 'D', 'C' }};
  14.        
  15.         char[] keys = {'D', 'B', 'D', 'C', 'C','D'};
  16.  
  17.         //******* Complete the code to count the number of correct answers for each
  18.         //******* student and print them.
  19.         for(int i=0;i<=answers.length-1;i++){
  20.             int c = 0;
  21.             for(int j=0;j<=answers[i].length-1;j++){
  22.                 if(answers[i][j]==keys[j]) c++;
  23.             }
  24.             System.out.printf("Student %d grade :%d%n",i,c);
  25.         }
  26.         int student, ans;
  27.         System.out.print("Enter the student and question number: ");
  28.         student = input.nextInt();
  29.         ans = input.nextInt();
  30.        
  31.         //******* Complete the code to print the student’s answer for the given
  32.         //******* question, and print whether it is correct or incorrect.
  33.         if(answers[student][ans]==keys[ans])
  34.             System.out.printf("The student answer was %s it is correct.",answers[student][ans]);
  35.         else
  36.             System.out.printf("The student answer was %s it is incorrect.",answers[student][ans]);
  37.     }
  38.    
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement