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

正在回答

4 回答

import java.util.Arrays;
public class HelloWorld {
    public static void main(String[] args) {
        int[] scores = {9 , -23 , 64 , 91 , 119 , 52 , 73};
        System.out.println("前三名成绩为:");
        HelloWorld hello = new HelloWorld();
        hello.topthree(scores);
    }
    public void topthree(int[] scores){
        Arrays.sort(scores);
        int count = 0;
        for(int i = scores.length - 1; i >= 0; i--) {
            if(scores[i] > 100 || scores[i] < 0) {
                continue;
            } //这里要加个括号,不然后面的代码都是这个if语句里的,逻辑上就不正确了
            count++;
            System.out.println(scores[i]);
            if(count >= 3)
                break;
        }
    }
} // 这里少了一个括号

把你上面的代码修改了一下,参考一下吧

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

https://img1.sycdn.imooc.com//5bfbc0e000011dd113350775.jpg还是不对。。

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

https://img1.sycdn.imooc.com//5bfb57450001aff005340471.jpg

由于你没有贴出你的代码,我给不好纠错,给你我的答案参考一下

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

https://img1.sycdn.imooc.com//5bfad5530001685407060498.jpg

可以参考一下我的

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

举报

0/150
提交
取消

8-1编程练习

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号