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

新人求助!!!运行后,一直都是5个数字,不是3个

新人求助!!!运行后,一直都是5个数字,不是3个

媛Yolanda 2018-04-23 01:28:29
import java.util.Arrays;public class HelloWorld {        //完成 main 方法    public static void main(String[] args) {        int[] scores={89, -23, 64, 91,119, 52, 73};        HelloWorld hello=new HelloWorld();        hello.max3(scores);    }        //定义方法完成成绩排序并输出前三名的功能        public void max3(int[] scores){        Arrays.sort(scores);        int nums=0;//定义一个变量,统计有效成绩的前三名的数量        System.out.println("考试成绩的前三名为:");                for(int i=scores.length-1; nums<3||i>=0; i--){            if(scores[i]<0||scores[i]>100){            continue;            }            nums++;            System.out.println(scores[i]);                    }    }    }
查看完整描述

1 回答

已采纳
?
林逸舟丶

TA贡献124条经验 获得超28个赞

nums<3||i>=0 你或许是想写 nums<3&&i>=0

查看完整回答
反对 回复 2018-04-23
  • 1 回答
  • 0 关注
  • 747 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信