//线性查找boolean flag=true;for(int i =0;i< array1.length;i++){if(array1[i]==4){
System.out.println("找到了,位置为"+i);
flag=false;break;}}if(flag){
System.out.println("无");}}}//二分法查找//所要查找的数组有序int[]arry2=newint[]{1,2,3,4,5,6,7,12};int dest1=3;int head=0;//初始的首索引int end=arry2.length-1;//初始的末索引boolean flag =true;while(head<=end){int middle =(head+end)/2;if(dest1==arry2[middle]){
System.out.println("找到了指定的元素,位置为:"+middle);
flag =false;break;}elseif(arry2[middle]>dest1){
end = middle-1;}else{//arry2[middle]<dest1
head = middle+1;}}if(flag){
System.out.println("没找到");}}}