java.util. Arrays.sort(scores);

import java.util.*;
public class ArraySortScore {
    
    //完成 main 方法
    public static void main(String[] args) {
        
        
        int counter=0;
        int[] scores=new int[]{89 , -23 , 64 , 91 , 119 , 52 , 73};
        SortScore(scores);
        int index=0;
        while(index<scores.length)
        {
            System.out.println(scores[index]);
            index+=1;
        }
        System.out.println("考试成绩的前三名为:");
        index=0;
        while(index<scores.length)
        {
            if(scores[index]>=0 && scores[index]<=100)
            {
                System.out.println(scores[index]);
                counter+=1;
                if(counter==3)
                    break;
            }
            index+=1;
        }
        
    }
    
    //定义方法完成成绩排序并输出前三名的功能
    public static void SortScore(int[] scores)
    {
       Arrays.sort(scores);
    }
    
    
    
    
    
    
    
    
    
}
---------- java ----------
-23
52
64
73
89
91
119
考试成绩的前三名为:
52
64
73

Output completed (0 sec consumed) - Normal Termination

 

posted @ 2017-05-12 10:59  sky20080101  阅读(291)  评论(0编辑  收藏  举报