首页 > 代码库 > HW6.19

HW6.19

技术分享

 

 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 the students: "); 9         int count = input.nextInt();10 11         String[] students = new String[count];12         double[] scores = new double[count];13 14         for(int i = 0; i < count; i++)15         {16             System.out.print("Enter a student‘s name: ");17             students[i] = input.next();18             System.out.print("Enter his score: ");19             scores[i] = input.nextDouble();20         }21 22         input.close();23 24         sortScore(students, scores);25 26         for(int i = count - 1; i >= 0; i--)27             System.out.printf("%s\t%f\n", students[i], scores[i]);28     }29 30     public static void sortScore(String[] strArray, double[] array)31     {32         double temp;33         String strTemp;34 35         for(int i = array.length - 1; i > 0; i--)36         {37             for(int j = 0; j < i; j++)38             {39                 if(array[j] > array[j + 1])40                 {41                     temp = array[j];42                     array[j] = array[j + 1];43                     array[j + 1] = temp;44                     strTemp = strArray[j];45                     strArray[j] = strArray[j + 1];46                     strArray[j + 1] = strTemp;47                 }48             }49         }50     }51 }

 

HW6.19