二分查找法123456789101112131415161718192021222324252627282930313233343536373839import java.util.Arrays;public class BinarySearch { //Find the number by changing the hight limit and lower limmit of the array. public static int rank(int key, int[] a, Counter n) { int lo = 0; int hi = a.length - 1; while(lo <= hi) { int mid = lo + (hi - lo) / 2; n.increment(); if(key < a[mid]) hi = mid - 1; else if(key > a[mid]) lo = mid + 1; else return mid; } return -1; } public static void main(String[] args) { //Print the number of the key that the whitelist has not. int[] whitelist = {1, 9, 4, 7, 8, 25, 11}; int[] key = {7, 2, 3, 15}; Counter n = new Counter("n"); Arrays.sort(whitelist); for(int i = 0; i < key.length; i++) { if(rank(key[i], whitelist, n) == -1) System.out.println(key[i]); } System.out.println("the check times is : " + n.tally()); }}