//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Example 2.8 on page 32
//  Testing the Binary Search

public class Ex0208
{ private static final int SIZE = 16;
  private static final int START = 40;
  private static final int RANGE = 20;
  private static int[] a = new int[SIZE];

  public static void main(String[] args)
  { Arrays.load(a,START,RANGE);
    Arrays.print(a);
    test();
    java.util.Arrays.sort(a);
    Arrays.print(a);
    test();
    test();
    test();
  }
  
  public static void test()
  { int x = Arrays.load(START,RANGE);
    System.out.print("Searching for x = " + x + ":\t");
    int i = Arrays.binarySearch(a,x);
    if (i >= 0) System.out.println("a[" + i + "] = " + a[i]);
    else System.out.println("i = " + i + " ==> x not found");
  }
}
