Small friends, according to the knowledge, write a JAVA program to achieve the output of the top three test results
Requirements:
1. Test results have been saved in the array scores, the array elements are 89, 23, 64, 91, 119, 52, 73
2, require a custom method to achieve the score ranking and output operations, the results array as a parameter passed in
3, the requirement to judge the effectiveness of the results (0-100), if the result is invalid, then ignore this score
Operating effect:
1 Public classHelloWorld {2 3 //complete the Main method4 Public Static voidMain (string[] args) {5 int[] scores = {89,-23, 64, 91, 119, 52, 73 };6Scores =Sortcustom (scores);7 for(intn = 0; n < 3; n++) {8 System.out.println (Scores[n]);9 }Ten } One A //define the method to finish sorting the scores and output the top three functions - Public Static int[] Sortcustom (int[] scores) { - intTMP = 0; the for(intk = 0; K < scores.length-1; k++) { - if(Scores[k] > | | scores[k] < 0) { - for(intm = scores.length-1; M > k; m--) { - if(Scores[m] <= && Scores[m] >= 0) { +TMP =Scores[m]; -SCORES[M] =Scores[k]; +SCORES[K] =tmp; A Break; at } - } - } -}//Put an irregular score in the rear - for(inti = 0; i < scores.length; i++) { - //Here is a custom sort, not using the sort of array in for(intj = i + 1; J < Scores.length; J + +) { - //ignore the nonstandard grades to if(Scores[j] > | | scores[j] < 0) { + Continue; - } the //Exchanging Data * if(Scores[j] >Scores[i]) { $TMP =Scores[i];Panax NotoginsengScores[i] =Scores[j]; -SCORES[J] =tmp; the } + } A } the returnscores; + } -}
The result of the operation is correct.
imooc-java-Homework Exercises-20150918