A. Design Ideas
1. Define a class Zhaoshuiwan, define a counter and initialize the list of suspects
2. in a for Loop, use the if statement to determine if the counter equals 0, if equal to 0 Continue to use the IF statement to determine if the ID is equal to the suspect, if the ID of the three suspects is different, The three counters are reduced by one until the counter is 0
3. in the main function, define a variable to record the number of posts
4. Enter the post ID with a for loop
5. call class Zhaoshuiwan, output a lot of three IDs
two. Code Implementation
Import Java.util.scanner;public class Zhaoshuiwanxu {public static void Zhaoshuiwan (int[] ID, int length,int[] Shuiwan) { Int[] Counter=new int[3]; Counter counter[0]=counter[1]=counter[2]=0; The first assignment is shuiwan[0]=shuiwan[1]=shuiwan[2]=-1; Initialize list of suspects for (int i=0;i<length;i++) {if (counter[0]==0) {C ounter[0]++; Shuiwan[0]=id[i]; } else if (counter[1]==0) {counter[1]++; Shuiwan[1]=id[i]; } else if (counter[2]==0) {counter[2]++; Shuiwan[2]=id[i]; } else if (id[i]==shuiwan[0])//If the counter is 0, re-assign the value {counter[0]++; } else if (Id[i]==shuiwan[1]) {counter[1]++; } else if (Id[i]==shuiwan[2]) {counter[2]++; }else//If the IDs of the three suspects are different, the three counters are reduced by one until the counter is 0 {counter[0]--; counter[1]--; counter[2]--; }}} public static void Main (string[] args) {int[] id=new int[100]; Post record form int[] Waterking=new int[3]; Three posts with a large number of IDs Scanner input=new Scanner (system.in); System.out.println ("Please enter the number of posts:"); int Num=input.nextint (); System.out.println ("Please enter the Post ID:"); for (int i=0;i<num;i++) {id[i]=input.nextint (); } Zhaoshuiwan (id,num,waterking); System.out.println ("Three posts a lot of ID is:"); for (int i=0;i<3;i++) {System.out.println (waterking[i]+ ""); } System.out.println (); }}
three. Implement
four. Personal Summary
In view of my poor programming ability, feel their own programming thinking, not so flexible, so I did not do it, but in the teacher's point of class, I know that the design idea is based on the last, in the expansion of 3 , add three suspected target, to traverse it can. So I borrowed from the previous seniors code implementation and know what each step means.
Software Engineering Personal Assignment 09