Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public static void main(String[] args) {
  2. LinearProbingHashST<String, String> st = new LinearProbingHashST<String, String>();
  3.  
  4. // reads the text file with collections of misspellings and corresponding
  5. // correct spelling of words and puts into hash table
  6. In dictionary = new In(args[0]);
  7. while (dictionary.hasNextLine()) {
  8. String misspelled = dictionary.readString();
  9. String corrected = dictionary.readLine().trim();
  10.  
  11. st.put(misspelled, corrected);
  12. }
  13. System.out.println();
  14.  
  15. // reads the second file of text with eventual misspellings and replaces
  16. // these with the correct ones
  17. Scanner sc = new Scanner(System.in);
  18. while (sc.hasNext()) {
  19. String next = sc.next();
  20. if (st.contains(next)) System.out.print(st.get(next) + " ");
  21. else System.out.print(next + " ");
  22.  
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement