本文介绍了公共静态诠释binarysearch()!我不知道它的正确形式.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
package binarysearch; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int []a = new int [8]; int low=0; int high=7; for(int i=0 ; i<a.length ; i++) { System.out.printf("\r\nPlease enter a number :",a[i]); a[i] = input.nextInt(); } System.out.printf("\r\nPlease enter an integer :"); int key = input.nextInt(); // System.out.printf("\r\nIt is in place "(binarysearch(numbers , low ,high ,key)"); public Static int binarysearch(int[]numbers,int key,int low , int high){ if(low>high) { return -1; } int mid = (low + high)/2 ; if(numbers [mid] == key){ return mid; if(key < numbers[mid]) { return binarysearch(numbers , low , mid-1 , key); } else{ return binarysearch(numbers , mid+1,high , key); System.out.printf("\r\nIt is in place "(binarysearch(numbers , low ,high ,key)"); } } } }
我将这段代码放在< pre></pre>之间.标签,以使其更具可读性和b)显示基本错误;
解决方案
这篇关于公共静态诠释binarysearch()!我不知道它的正确形式.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!