逆序输出的问题
逆序的问题大家是怎么理解的呢 为什么在这里要用逆序输出前三名的成绩呢
逆序的问题大家是怎么理解的呢 为什么在这里要用逆序输出前三名的成绩呢
2018-07-19
Arrays.sort();这个是升序遍历输出数组中的内容,但是用sort也可以输出下面的代码就是用sort输出的,参考一下,<*.*>
import java.util.Arrays;
public class HelloWorld {
public static void main(String[] args) {
int[] scores={89,-23,64,91,119,52,73};
HelloWorld hello=new HelloWorld();
int[] scoress=new int[scores.length];
for(int i=0;i<scores.length;i++){
if(scores[i]<0||scores[i]>100){
continue;
}else{
scoress[i]=scores[i];
}
}
hello.topthree(scoress);
}
public void topthree(int[] scoress){
Arrays.sort(scoress);
System.out.println("考试成绩的前三名为:");
System.out.println(scoress[scoress.length-1]);
System.out.println(scoress[scoress.length-2]);
System.out.println(scoress[scoress.length-3]);
}}
举报