1 import java.util.Scanner; 2 3 /** 4 * @author Administrator 折半查找 5 */ 6 public class zhebansousuo { 7 8 public static void main(String[] args) { 9 int[] a = new int[100]; 10 int x, b; 11 Scanner cin = new Scanner(System.in); 12 x = cin.nextInt(); 13 14 for (int i = 0; i < x; i++) { 15 a[i] = cin.nextInt(); 16 } 17 b = cin.nextInt(); 18 System.out.println(sea(a, b, 0, x)); 19 20 } 21 22 public static int sea(int[] a, int x, int beg, int last) { 23 int mid; 24 if (beg > last) { 25 return -1; 26 } 27 while (beg <= last) { 28 mid = (beg + last) / 2; 29 if (x == a[mid]) { 30 return mid; 31 } else if (a[mid] < x) { 32 beg = mid + 1; 33 } else if (a[mid] > x) { 34 last = mid - 1; 35 } 36 } 37 return -1; 38 } 39 40 }