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

求大神解答8-1

错的:

public class HelloWorld {

    public static void main(String[] args) {

        int[] scores=new int[]{89,-23,64,91,119,52,73};

        HelloWorld hello=new HelloWorld();

        hello.rank(scores);}        

    public void rank(int[] arrays){

    int[] score=new int[7];

    for(int i=arrays.length-1;i>=0;i--){

        if(arrays[i]<0&&arrays[i]>100){continue;}

       else

        score[i]=arrays[i];}

    Arrays.sort(score);

    System.out.println(score[6]+"\n"+score[5]+"\n"+score[4]);}}

对的:

import java.util.Arrays;

public class HelloWorld {

    public static void main(String[] args) {

        int[] scores=new int[]{89,-23,64,91,119,52,73};

        HelloWorld hello=new HelloWorld();

        hello.rank(scores);}        

    public void rank(int[] arrays){

    int[] score=new int[7];

    for(int i=arrays.length-1;i>=0;i--){

        if(arrays[i]>=0&&arrays[i]<=100){ score[i]=arrays[i];}

       else continue;}

    Arrays.sort(score);

    System.out.println(score[6]+"\n"+score[5]+"\n"+score[4]);}}



提问者:RanEr不知道 2016-03-25 11:35

个回答

  • tickwu
    2016-03-25 13:01:50
    已采纳

    public class HelloWorld {
        public static void main(String[] args) {
            int[] scores=new int[]{89,-23,64,91,119,52,73};
            HelloWorld hello=new HelloWorld();
            hello.rank(scores);}        
        public void rank(int[] arrays){
            int[] score=new int[7];
            for(int i=arrays.length-1;i>=0;i--){
                if(arrays[i]<0||arrays[i]>100{
                    continue;}
                else
                    score[i]=arrays[i];
              }
            Arrays.sort(score);
             System.out.println(score[arrays.length-1]+"\n"+score[arrays.length-2]+"\n"+score[arrays.length-3]);}
    }