001package algs52; // section 5.2 002import stdlib.*; 003import algs35.SET; 004/* *********************************************************************** 005 * Compilation: javac SpellChecker.java 006 * Execution: java SpellChecker words.txt 007 * Dependencies: StringSET.java In.java 008 * 009 * Read in a dictionary of words from the file words.txt, and print 010 * out any misspelled words that appear on standard input. 011 * 012 *************************************************************************/ 013 014public class XSpellChecker { 015 016 public static void main(String[] args) { 017 SET<String> dictionary = new SET<>(); 018 019 // read in dictionary of words 020 In dict = new In(args[0]); 021 while (!dict.isEmpty()) { 022 String word = dict.readString(); 023 dictionary.add(word); 024 } 025 StdOut.println("Done reading dictionary"); 026 027 // read strings from standard input and print out if not in dictionary 028 StdOut.println("Enter words, and I'll print out the misspelled ones"); 029 while (!StdIn.isEmpty()) { 030 String word = StdIn.readString(); 031 if (!dictionary.contains(word)) StdOut.println(word); 032 } 033 } 034}