各位大神错在哪里,为什么{:2_43:}
有木有闲的蛋疼的大神没事带我飞啊
- public class erfen{
-
- public static void main(String[] args){
-
- int[] a = {1,3,4,5,7,8,9,10,23,25,29,33,35};
- int mubiao = 10;
- int xia = binarySearch(a,mubiao);
-
- System.out.println((mubiao==-1)?mubiao + "元素不存在!":mubiao + "在数组中的下标是" + xia);
- }
-
- public static int binarySearch(int[] a,int mubiao){
- int kaishi = 0;
- int jieshu = a.length-1;
- int zhongjian = (kaishi + jieshu)/2;
-
- while(zhongjian >= jieshu){
-
- if(a[zhongjian]==mubiao){
- return zhongjian;
- }else if (a[zhongjian]>mubiao){
- jieshu = zhongjian -1;
- }else if(a[zhongjian]<mubiao){
- jieshu = zhongjian +1;
- }
- }
- return -1;
- }
-
-
- }
-
复制代码 |
|