首页 > 编程 > Java > 正文

JAVA--定义一个包含整型数组参数的方法,用来接收成绩数组,进行成绩排序并输出前三名

2019-11-08 03:04:14
字体:
来源:转载
供稿:网友
import java.util.Arrays;public class HelloWorld {    //完成 main 方法    public static void main(String[] args) {                int[] scores= {89 , -23 , 64 , 91 , 119 , 52 , 73};        System.out.PRintln(Arrays.toString(scores));                HelloWorld hello=new HelloWorld();        hello.big3(scores);            }    //定义方法完成成绩排序并输出前三名的功能    public void big3(int[] scores){        Arrays.sort(scores);        int num = 0;        for(int i = scores.length-1;i>=0&&num<3;i--)        {            if(scores[i]<0 ||scores[i]>100)                continue;            num++;            System.out.println(scores[i]);        }    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表