折半查找法
public static void main(String[] args) { int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, top, bot, mid=-1, m = 3; top = 0; bot = 9; while (top <= bot) { mid = (top + bot) / 2; if (a[mid] == m) { break; } else if (a[mid] < m) { top = mid + 1; } else { bot = mid - 1; } }
if(top<=bot){
System.out.println(mid+"");
}else {
System.out.println("...");
}
}