01: import java.util.Arrays;
02: import java.util.Scanner;
03: 
04: /**
05:    This program tests the binary search algorithm.
06: */
07: public class BinarySearchTester
08: {  
09:    public static void main(String[] args)
10:    {  
11:       // Construct random array
12:    
13:       int[] a = ArrayUtil.randomIntArray(20, 100);
14:       Arrays.sort(a);
15:       ArrayUtil.print(a);
16:       BinarySearcher searcher = new BinarySearcher(a);
17:       Scanner in = new Scanner(System.in);
18: 
19:       boolean done = false;
20:       while (!done)
21:       {
22:          System.out.print
23:                ("Enter number to search for, -1 to quit:");
24:          int n = in.nextInt();
25:          if (n == -1) 
26:             done = true;
27:          else
28:          {
29:             int pos = searcher.search(n);
30:             System.out.println("Found in position " + pos);
31:          }
32:       }
33:    }
34: }