01: import java.util.Arrays;
02: import javax.swing.JOptionPane;
03: 
04: /**
05:    This program tests the binary search algorithm.
06: */
07: public class BinarySearchTest
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: 
18:       boolean done = false;
19:       while (!done)
20:       {
21:          String input = JOptionPane.showInputDialog(
22:             "Enter number to search for, Cancel to quit:");
23:          if (input == null) 
24:             done = true;
25:          else
26:          {
27:             int n = Integer.parseInt(input);
28:             int pos = searcher.search(n);
29:             System.out.println("Found in position " + pos);
30:          }
31:       }
32:       System.exit(0);
33:    }
34: }