首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。