package ok;
import java.util.Arrays;
public class Demo {
public static void main(String[] args) {
Demo hello=new Demo();//创建对象
int [] scores= {89,-23,64,91,119,-45,78,168};
System.out.println("考试成绩前三名为");
hello.result(scores);//调用无返回值的方法
}
public void result(int[] scores)
{
Arrays.sort(scores);//从小到大排序
int count=0;//定义变量来记录取的个数
for(int i=scores.length-1;i>=0;i--)//所以要倒序循环取后三个
{
if(scores[i]<0||scores[i]>100)
{continue;}
count++;
System.out.println(scores[i]);
if(count==3)
{break;}
}
}
}
输出考试成绩前三名
最新推荐文章于 2023-01-16 13:11:32 发布