怎么將所有正確的成績都打印出來呢?
答案里面只是負數的分數剔除出去了,怎么把原來的數組中的負數剔除并將正確的所有分數一起顯示出來呢?
比如運行結果是:
原成績:67 89 66 87 -23 56
正確成績為:67 89 66 87 56
前三名成績為:89 87 67
請問這樣怎么寫啊?
答案里面只是負數的分數剔除出去了,怎么把原來的數組中的負數剔除并將正確的所有分數一起顯示出來呢?
比如運行結果是:
原成績:67 89 66 87 -23 56
正確成績為:67 89 66 87 56
前三名成績為:89 87 67
請問這樣怎么寫啊?
2018-12-01
舉報
2019-05-23
?import java.util.Arrays;
?public class T8 {?
? ? ? ? ? public static void main(String[] args) {
? ? ? ? int scores[]={67,89,66,87-23,56};
? ? ? ? ?T8 hell= new T8();
? ? ? ? System.out.println("前三名");
? ? ? ? hell.aaa(scores);
public void aaa(int[]scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int num =0;
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ??
? ? ? ? ? ?if(scores[i]<0||scores[i]>100) {
? ? ? ? ? ?continue;
? ? ? ? ? ?}
? ? ? ??
? ? ? ??
? ? ? ? num++;
? ? ? ? if(num>3){
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? System.out.println(scores[i]);
? ? }
? ? }
}
? ? ? ??