1.顺序查找
从头到尾遍历
for(int i = 0;i<is.length;i++){
if(is[i] == num){
System.out.println("查找到了");
}
}
2.二分法查找
前提:先排序
public static void main(String[] args){
int[] is = {39,77,27,20,45,62};
int num = 77;
//排序
Arrays.sort(is);
int start = 0;
int end = is.length-1;
while(start <= end){
int mid = (start+end)/2;
if(num >is[mid]){
start = mid+1;
}else if(num < is[mid]){
end = mid-1;
}else{
System.out.println("查找到了");
break;
}
}
}
}