problem with recursive binary search program
Hi,
I am trying to create a recursive binary search program as follows
import java.io.*;
class SearchArray
{
int a[];
public static int binarySearch(int[] a,int ser)
{
System.out.println("Elements of the array are");
for(int i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
int len = a.length;
int beg =a[0];
int end =a[len];
int mid = (beg + end)/2;
if(a[mid] > ser)
{
for(i=0;i<mid;i++)
int k[i] = a[i];
return binarySearch(k,ser); //trying to call recursively
}
else if(a[mid] < ser)
{
for(i=0;i<=mid+1;i++)
int k[i] = a[i]; //giving error
return binarySearch(k,ser); //trying to call recursively
}
else
System.out.println(mid);
}
}
class Result
{
public static void main(String args[])
{
SearchArray ob = new SearchArray();
int a[] = {1,2,4,5,8,9,10,11,13};
int b = 5;
ob.binarySearch(a,b);
}
}
DETAILS:
1)I am passing the array a and search element b from Result class.
2)returning and calling the method binarySearch within the same class.
---->The error it is showing is as follows
C:\java_programs>javac Result.java
Result.java:19: '.class' expected
int k[i] = a[i];
^
Result.java:19: not a statement
int k[i] = a[i];
^
Result.java:25: '.class' expected
int k[i] = a[i];
^
Result.java:25: not a statement
int k[i] = a[i];
^
4 errors
can anyone pls rectify this error and tell me what conceptual mistake I am doing in this program?