import java.util.Scanner;
public class Chhalengeofbinarysearch {
public static void main(String[] args) {
int[] array = takesinput();
System.out.println("enter the value of iteam");
Scanner scn = new Scanner(System.in);
int iteam = scn.nextInt();
int nilesh = returnindex(array,iteam);
System.out.println(nilesh);
}
//takesinput function
public static int[] takesinput() {
System.out.println("enter the size of array");
Scanner scn = new Scanner(System.in);
int N = scn.nextInt();
int[] arr = new int[N];
for (int i = 0; i < arr.length; i++) {
System.out.println("enter the value for" + i + "index in asending or decending order");
arr[i] = scn.nextInt();
}
return arr;
}
// returnindex function
public static int returnindex(int [] arr ,int iteam) {
int lo =0;
int higher= arr.length ;
while(lo<=higher) {
int mid =(lo+higher)/2;
if(arr[mid]<iteam) {
lo=mid+1;
}
else if (arr[mid]>iteam) {
higher=mid-1;
}
else
return mid;
}
return -1;
}
}
and output is
compiling failed with exitcode 1,…why?