public class OrderedArray { //有序数组的二分查找; public int find(int arr[],int key){ int lowerBound = 0; int upperBound = arr.length - 1; int curIn; while(true){ curIn = (lowerBound + upperBound)/2; if(arr[curIn] == key){//找到了 return curIn; } else if(lowerBound > upperBound){//没找到 return arr.length; } else{ if(arr[curIn] < key){ lowerBound = curIn + 1; } else{ upperBound = curIn - 1; } } } } public static void main(String[] args) { int[] t = {1,2,3,4,5,6,7,8,9,10}; OrderedArray o = new OrderedArray(); System.out.println(o.find(t,11)); } }