01: /**
02:    A class for executing linear searches through an array.
03: */
04: public class LinearSearcher
05: {  
06:    /**
07:       Constructs the LinearSearcher.
08:       @param anArray an array of integers
09:    */
10:    public LinearSearcher(int[] anArray)
11:    {
12:       a = anArray;
13:    }
14: 
15:    /**
16:       Finds a value in an array, using the linear search 
17:       algorithm.
18:       @param v the value to search
19:       @return the index at which the value occurs, or -1
20:       if it does not occur in the array
21:    */
22:    public int search(int v)
23:    {  
24:       for (int i = 0; i < a.length; i++)
25:       {  
26:          if (a[i] == v)
27:             return i;
28:       }
29:       return -1;
30:    }
31: 
32:    private int[] a;
33: }