标签:middle sharp system out == art bre ring har
public class Demo { public static void main(String[] args){ int[] num = {1,2,3,4}; int index = 3; int start = 0; int end = num.length-1; boolean flag = false; if(index>=num[0]&&index<=num[end]){ while(index<=num[end]){ int middle = (start + end)/2; if(index==num[middle]){ System.out.println(middle); flag = true; break; } if(index<num[middle]){ end = middle-1; } if(index>num[middle]){ start = middle+1; } } } if(flag==false){ System.out.println("没有找到"); } } }
标签:middle sharp system out == art bre ring har
原文地址:https://www.cnblogs.com/yanxiaoge/p/10654520.html