JAVA实现二分法

import java.util.Arrays;
/*
 * 11.18
 * 二分法
 * 
 * 
 */

public class SearchTest03 {
	public static void main(String[] args){
	int [] a={10,15,13,5,65,70,43};
	Arrays.sort(a);
	for(int num:a){
		System.out.print(num+" ");
	}
	
	System.out.println(binarySearch(a,15));
}
	public static String binarySearch(int [] arry,int num){
		int begin=0;
		int end=arry.length-1;
		while(begin<=end){
			int mid=(begin+end)/2;
			if(arry[mid]==num){
				return "您要找的数下标是"+mid;
			}else {
				if(arry[mid]>num)
					end=mid-1;
				if(arry[mid]

 

你可能感兴趣的:(JAVA基础)