问答详情
源自:7-1 编程练习

怎么成绩全是0

import java.util.*;
public class HelloWorld {   
    //完成 main 方法
    public static void main(String[] args) {
        int[] scores = {89,-23,64,91,119,52,73};

        TopE(scores);
        
        
    }
    
    //定义方法完成成绩排序并输出前三名的功能
    
    public  static void TopE(int[] in) {
        int count = 0;
        int[] ab = new int[3];
        int j = 0;
        try{
            for(int i = in.length; i >= 0; i--) {
            if(in[i]>0 && in[i]<100) {
                ab[j++] = in[i];
                count++;
            if(count > 3)
                break;
            }else {continue;}

        }
           }catch (Exception e) {}
            System.out.println("考试成绩的前三名为:");
        Arrays.sort(ab);
        System.out.println(Arrays.toString(ab));
    }
    
        
}

提问者:自小生来神气壮 2016-06-22 00:41

个回答

  • lsd0421at
    2016-06-22 10:25:22

    package com.imooc;
    import java.util.Arrays;
    import java.util.Scanner;
    public class HelloWord {
     public static void main(String[] args){
      HelloWord hello=new HelloWord();
      int[] scores={89 , -23 , 64 , 91 , 119 , 52 , 73};
      System.out.println("考试的前三名为:");
      hello.third(scores);
           
     }


     public void third(int[] scores) {
      // TODO Auto-generated method stub
      Arrays.sort(scores);
      int count=0;
      for(int i=scores.length-1;i>=0;i--){
       if(scores[i]<0||scores[i]>100) continue;
       count++;
       if(count<=3) System.out.println(scores[i]);
      }
     }
    }