public class Linear
{
    /** Linear search for who in array a.
	Precondition: a is not null
	Postcondition: return a value k such that a[k] == who; 
		return -1 if there is no such k
    */
    public static int linearSearch(int[] a, int who) {
	for (int k = 0; k < a.length; k++) {
	    // who has not been found yet, i.e. all 
	    // values a[0],a[1],...,a[k-1] are different than who
	    if (a[k] == who)
		return k;
	}
	return -1;
    }

    public static void main (String[] args) {
	int[] j = {5,7,2,3,8,4};
	System.out.println("8 is at position " + linearSearch(j, 8));
	System.out.println("6 is at position " + linearSearch(j, 6));
    }
}
