import java.util.ArrayList; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; import javax.swing.JOptionPane; public class LinearSearch // could also be called "sequential search" { ArrayList words = new ArrayList(); // constructor public LinearSearch() throws IOException { FileReader reader = new FileReader("C:/Temp/Top1000Words.txt"); BufferedReader in = new BufferedReader(reader); String word; for (int k = 0; k < 1000; k++) { word = in.readLine(); System.out.println(k + " " + word); words.add(word); } } public void search() { String toFind = JOptionPane.showInputDialog("Which word are you looking for?"); boolean found = false; int counter = 0; String word = ""; while ( ! found && counter < 1000) { word = words.get(counter); if (toFind.equalsIgnoreCase(word)) { found = true; JOptionPane.showMessageDialog(null, toFind + " is in the list of the most common 1000 English words."); } counter++; } if ( ! found) JOptionPane.showMessageDialog(null, toFind + " is NOT in the list of the most common 1000 English words."); } public static void main(String [] args) throws IOException { LinearSearch s = new LinearSearch(); s.search(); } }