首页 > 代码库 > HW7.3

HW7.3

技术分享

 

 1 public class Solution 2 { 3     public static void main(String[] args) 4     { 5         char[][] answers =  6         { 7             {‘A‘, ‘B‘, ‘A‘, ‘C‘, ‘C‘, ‘D‘, ‘E‘, ‘E‘, ‘A‘, ‘D‘},  8             {‘D‘, ‘B‘, ‘A‘, ‘B‘, ‘C‘, ‘A‘, ‘E‘, ‘E‘, ‘A‘, ‘D‘},  9             {‘E‘, ‘D‘, ‘D‘, ‘A‘, ‘C‘, ‘B‘, ‘E‘, ‘E‘, ‘A‘, ‘D‘}, 10             {‘C‘, ‘B‘, ‘A‘, ‘E‘, ‘D‘, ‘C‘, ‘E‘, ‘E‘, ‘A‘, ‘D‘}, 11             {‘A‘, ‘B‘, ‘D‘, ‘C‘, ‘C‘, ‘D‘, ‘E‘, ‘E‘, ‘A‘, ‘D‘}, 12             {‘B‘, ‘B‘, ‘E‘, ‘C‘, ‘C‘, ‘D‘, ‘E‘, ‘E‘, ‘A‘, ‘D‘}, 13             {‘B‘, ‘B‘, ‘A‘, ‘C‘, ‘C‘, ‘D‘, ‘E‘, ‘E‘, ‘A‘, ‘D‘}, 14             {‘E‘, ‘B‘, ‘E‘, ‘C‘, ‘C‘, ‘D‘, ‘E‘, ‘E‘, ‘A‘, ‘D‘}15         };16 17         char[] keys = {‘D‘, ‘B‘, ‘D‘, ‘C‘, ‘C‘, ‘D‘, ‘A‘, ‘E‘, ‘A‘, ‘D‘};18         int[] students = new int[10];19         int[] correctCount = new int[10];20         int temp;21 22         for(int i = 0; i < 10; i++)23             students[i] = i;24         for(int i = 0; i < answers.length; i++)25         {26             for(int j = 0; j < answers[i].length; j++)27                 if(answers[i][j] == keys[j])28                     correctCount[i]++;29         }30 31         for(int i = 0; i < 10; i++)32         {33             for(int j = i; j < 10; j++)34             {35                 if(correctCount[j] > correctCount[i])36                 {37                     temp = correctCount[j];38                     correctCount[j] = correctCount[i];39                     correctCount[i] = temp;40                     temp = students[j];41                     students[j] = students[i];42                     students[i] = temp;43                 }44             }45         }46 47         for(int i = 0; i < 10; i++)48             System.out.println("Student " + students[i] + "‘s correct count is " + correctCount[i]);49     }50 }

 

HW7.3