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)"); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)