import java.util.Arrays; import java.util.Scanner; public class Test13 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("***************"); System.out.println("二分查找"); System.out.println(" 作者:EREC"); System.out.println("***************"); int a[]={1,3,4,6,8}; System.out.println("输入你要查找的数字:"); int n = input.nextInt();//输入数字 int i = 0, j = a.length - 1; while (i <= j) { int m = (j + i)>>>1; //一半取整 if (a[m] < n) i = m + 1;//目标在右边 else if (n < a[m]) j = m - 1;//目标在左边 else { int b=m+1; System.out.println("数字在:"+b); return;//找到结果 } } System.out.println("数字找不到"); } }