01: import javax.swing.JOptionPane;
02: 
03: /**
04:    This program tests the linear search algorithm.
05: */
06: public class LinearSearchTest
07: {  
08:    public static void main(String[] args)
09:    {  
10:       // construct random array
11:    
12:       int[] a = ArrayUtil.randomIntArray(20, 100);
13:       ArrayUtil.print(a);
14:       LinearSearcher searcher = new LinearSearcher(a);
15: 
16:       boolean done = false;
17:       while (!done)
18:       {
19:          String input = JOptionPane.showInputDialog(
20:             "Enter number to search for, Cancel to quit:");
21:          if (input == null) 
22:             done = true;
23:          else
24:          {
25:             int n = Integer.parseInt(input);
26:             int pos = searcher.search(n);
27:             System.out.println("Found in position " + pos);
28:          }
29:       }
30:       System.exit(0);
31:    }
32: }