Package test2; Import java.util.Scanner; / * * Looking Wang water * / public class test2 { public static void main (String [] args) { int [] A = null ; // stored message ID Scanner SC = new new Scanner (the System.in); System.out.println ( "Please enter the number of total posts:" ); int NUM = sc.nextInt (); A = new new int [NUM]; int D = 0 ;; for ( int i=0;i<num;i++){ d=i+1; System.out.print("请输入第"+d+"个帖子数:"); a[i]=sc.nextInt(); } int id = 0; int c=0; for(int i=0;i<a.length;i++) { if(c==0) { id=a[i]; c=1; }else if(c>0){ if(a[i]==id) { C = C +. 1 ; } the else IF (! A [I] = ID) { C = C-. 1 ; } } } System.out.println ( "King ID for the water:" + ID); } }
This is traversed only once, by a for loop to find water king