Scanner;
public class BinarySequentialSearch
{
static Scanner console = new Scanner (System.in);
public static void main(String[ ] args)
{
int num,c, first, last, middle, n, search, array[];
Scanner in = new Scanner(System.in);
array = new int[20];
System.out.print("Enter 20 integers : ");
for (c = 0; c < array.length; c++)
array[c] = in.nextInt();
int i = 0;
boolean found = false;
if (found)
{
int loc = i + 1;
System.out.println("\n"+"\t"+"Status"+"\t"+"\t"+": "+"Success");
System.out.println("\t"+"Found " + " at index : " + i +"");
System.out.println("\t"+"Number of comparison : " + loc +"\n");
}
else
{
System.out.println("\n"+"\t"+"Fail. "+ key + " is not in this
array."+"\n");
}
first = 0;
last = array.length - 1;
middle = (first + last)/2;
int count = 0;
while(first <= last)
{
System.out.println("\n"+"\t"+"Status"+"\t"+"\t"+": "+"Success");
System.out.println("\t"+"Found " + " at index : " +
(middle));
System.out.println("\t"+"Number of comparison : " + (count
+ 1) +"\n");
System.out.println("\n"+"Conclusion : Binary search is the better and easy than
Sequential Search."+"");
break;
}
else
{
last = middle - 1;
}
middle = (first + last)/2;
}
if ( first > last )
}
}
}