UNB/ CS/ David Bremner/ teaching/ java/ Lsearch.java
import ccj.*;

public class Lsearch
{  public static void main(String[] args)
   {  int[] v = new int[20];
      int i;
      for (i = 0; i < v.length; i++)
         v[i] = Numeric.randomInt(1, 100);
      print(v);
      System.out.print("Enter number to search for: ");
      int n = Console.in.readInt();
      int j = linearSearch(v, n);
      System.out.println("Found in position " + j);
   }

   public static int linearSearch(int[] v, int a)
   {  int i;
      for (i = 0; i < v.length; i++)
      {  if (v[i] == a)
            return i;
      }
      return -1;
   }

   public static void print(int[] a)
   {  int i;
      for (i = 0; i < a.length; i++)
         System.out.print(a[i] + " ");
      System.out.println();
   }
}