Classroom Exercises (Water king extension)

Source: Internet
Author: User

Design ideas:

Similar to the previous experiment, but also the use of the idea of elimination, the difference is that this is the first to determine the three ID, they do not phase between the elimination, the last remaining three ID is three of the king;

Code:

Package Text;import Java.util.Scanner; Public classtext_y { Public Static voidMain (string[] args) {Scannerinch=NewScanner (System.inch); intN; System. out. println ("Please enter the total number of posts:"); N=inch. Nextint (); String list[]=NewString[n]; inti; System. out. println ("Please enter ID:");  for(i=0; i<n;i++) {List[i]=inch. Next (); }         intj[]=New int[3];//mark the convenience of each water king with Jj[0]=j[1]=j[2]=0; String id[]=Newstring[3];//set a single water king ID          for(i=0; i<n-1; i++)         {             if(j[0]==0)//when the counter is 0 o'clock, re-give the water king ID{j[0]++; id[0]=List[i]; }             Else if(j[1]==0) {j[1]++; id[1]=List[i]; }             Else if(j[2]==0) {j[2]++; id[2]=List[i]; }                          Else if(List[i].equals (id[0]))//counter increases when same ID{j[0]++; }             Else if(List[i].equals (id[1]) {j[1]++; }             Else if(List[i].equals (id[2]) {j[2]++; }                          Else//22-Phase extinction counter is reduced with different IDs{j[0]--; j[1]--; j[2]--; }} System. out. println ("The three water kings were:"+id[0]+"   "+id[1]+"   "+id[2]); inch. Close (); }}

Results:

Personal Summary:

Because the design thinking is similar to the last time, so good thinking after the good work.

Classroom Exercises (Water king extension)

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.