为了账号安全,请及时绑定邮箱和手机立即绑定

为什么是这样

public class HelloWord {
    //完成 main 方法
    public static void main(String[] args) {
        int[] score={89,-23,64,91,119,52,73};
        HelloWord he=new HelloWord();
        he.scoreSort(score);


    }

    //定义方法完成成绩排序并输出前三名的功能

    public void scoreSort(int[] scores){
        System.out.println("考试成绩的前三名为:");
        Arrays.sort(scores);
        int count=1;
        for(int i=scores.length-1;i>=0;i--){
            count++;
            System.out.println(scores[i]);
            if(scores[i]<0||scores[i]>100){
                continue;
            }
            if(count>3){
                break;
            }
        }
    }
}

结果是

考试成绩的前三名为:
119
91
89

正在回答

2 回答

变量的输出不能使用逗号相连的,使用+号

ftrqcs

0 回复 有任何疑惑可以回复我~

找到原因了,是位置写错了

public void scoreSort(int[] scores){
    System.out.println("考试成绩的前三名为:");
    Arrays.sort(scores);
    int count=1;
    for(int i=scores.length-1;i>=0;i--){
        //count++;
        //System.out.println(scores[i]);
        if(scores[i]<0||scores[i]>100){
            continue;
        }
        count++;
        System.out.println(scores[i]);
        if(count>3){
            break;
        }
    }
}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Java入门第一季(IDEA工具)升级版
  • 参与学习       1162721    人
  • 解答问题       17548    个

0基础萌新入门第一课,从Java环境搭建、工具使用、基础语法开始

进入课程

为什么是这样

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信