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 }
时间: 2024-11-10 13:21:03

HW7.3的相关文章

HW7.12

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 double[] rates = {0.10, 0.15, 0.25, 0.28, 0.33, 0.35}; 8 int[][] brackets = 9 { 10 {8350, 33950, 82250, 171550, 372950}, 11 {16700, 67900, 137050

HW7.14

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter the size for the matrix: "); 9 int size = input.nextInt(); 10 11 input.clo

HW7.13

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter the number of rows and columns of the array: "); 9 int row = input.nextInt

HW7.18

1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 int[][] m = {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}}; 6 7 shuffle(m); 8 9 for(int i = 0; i < m.length; i++) 10 { 11 for(int j = 0; j < m[0].length; j++) 12 System.out.print(

HW7.17

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 9 int n = input.nextInt(); 10 int limit = input.nextInt(); 11 12 int[][] borrowers = new int[n][n]; 13

HW7.1

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 double[][] matrix = new double[4][4]; 9 System.out.print("Enter a 4-by-4 matrix row by row: "); 10

HW7.2

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 int[][] matrix = new int[4][4]; 9 System.out.println("Enter a 4-by-4 matrix row by row: "); 10 for

HW7.16

1 import java.util.Arrays; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 int row = (int)(Math.random() * 10); 8 int column = (int)(Math.random() * 10); 9 int[][] array = new int[row][column]; 10 11 for(int i = 0; i < ro

HW7.11

1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter a number between 0 and 511: "); 9 int number = input.nextInt(); 10 11 inpu