import java.io.*; import java.util.Enumeration; import jds.Set; import jds.collection.SortedSet; import jds.util.StringCompare; class SpellCheck { private static Set readWords (Reader in) throws IOException { Set result = new SortedSet(new StringCompare()); StreamTokenizer tok = new StreamTokenizer(in); tok.ordinaryChar('.'); tok.lowerCaseMode(true); int c = tok.nextToken(); while (c != StreamTokenizer.TT_EOF) { if (c == StreamTokenizer.TT_WORD) { result.addElement(tok.sval); } c = tok.nextToken(); } return result; } static public void main (String [ ] args) { try { // read the two sets of words Set dict = readWords(new FileReader("words")); Set doc = readWords(new FileReader("input")); // remove the correctly spelled words doc.differenceWith(dict); // now print the misspellings Enumeration e = doc.elements(); while (e.hasMoreElements()) System.out.println(e.nextElement()); } catch (IOException e) { System.err.println("exception:"+e); } } }