ImportJava.util.*;classExample2_5 { Public Static voidMain (String args[]) {intStart=0, End,middle; intA[] = {12,45,67,89,123,-45,67}; intN =a.length; for(inti=0; i<n; i++) {//sorting arrays by Selection for(intj = i+1; J < n;j++){ if(A[j] <A[i]) { intt =A[j]; A[J]=A[i]; A[i]=T; }}} System.out.println (Arrays. toString (a)); Scanner Scanner=NewScanner (system.in); System.out.println ("Enter an integer, and the program determines whether the integer is in the array:"); intNumber =Scanner.nextint (); intCount =0 ; End=N; Middle= (start+end)/2; while(number!=A[middle]) { if(number>A[middle]) Start=Middle; Else if(number<A[middle]) End=Middle; Middle= (start+end)/2; Count++; if(COUNT>N/2) Break; } if(COUNT>N/2) System.out.printf ("%d is not in array. \ n", number); ElseSystem.out.printf ("%d in the array. \ n", number); }}
The Java application determines whether an integer entered by the user is in the known quantity group.