码迷,mamicode.com
首页 > 其他好文 > 详细

HW6.19

时间:2016-08-26 22:47:01      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 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

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5811825.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!