/** This program is intended to be used with the book "Java 7 -- What Do You Want To Do?"
 * by Steven P. Warr and is distributed free of charge and without and expectations of remuneration.
 * Chapter ALG   NOTE most program names begin with the title of the chapter in which
 * they are intended to be used.   Copyright 2010 Steven P. Warr All rights reserved
 */

import java.util.*; 
import java.io.*; 
public class Alg01 
{
    public static void main(String[ ] args) throws IOException
    {
		Scanner infile = new Scanner(new File("alg01.data"));
		Scanner keyIn = new Scanner(System.in);	
		String key = "";
		int count = 0;
		String [] list = new String[100];
		int x = 0;
		while (infile.hasNext())   // read the array from file
		     {
				list[x] = infile.next ();
				System.out.println(list[x]);
				x++;
		     }	
		count = x;
	
		System.out.println("Enter a word to search for");
		key = keyIn.next();
	
		x = -1;        //notice the x++ inside the do loop.  If you started with		
		do		// x = 0, the first array element would be skipped
			{    
				x++;
			}
		while (x < count && !list[x].equals(key)); //notice the !
		if (x == count)
			System.out.println(key + " was not found.");
		else
			System.out.println(key + " is located at "+ x);
  	}
}  