imooc-java-Homework Exercises-20150918

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.