import java.io.BufferedReader; import java.io.FileReader; import java.util.HashMap; import java.util.Scanner; /** * A Little class to implement a recursive method for cutting down words. * The idea is to see if a given work can have one letter progressively removed, such that * after each removal the word remais a valid word. Until you reach two letters * For instance: packer .. pacer .. pace .. ace .. ce * Some may complain that ce is not a word. It is in the dictionary I used. */ public class Worder { /** Hashmap of english words. Every value is 1. The only significant thing is whether * or not the key exists */ HashMap words; /** * Initialize the class. This is mostly just reading a set of words into a hashtable */ public Worder() { words = new HashMap<>(); // this file exists on Mac and Linux. It certainly does not exist on Windows try (BufferedReader br = new BufferedReader(new FileReader("/usr/share/dict/words"))) { String l; while (null != (l=br.readLine())) { words.put(l.trim(), 1); } } catch (Exception ee) { ee.printStackTrace(); } } /** * Return true iff the word is in english * @param s the word to check * @return true iff the word is in english */ public boolean isEnglish(String s) { return words.containsKey(s); } /** * Remove the nth letter from a string * @param n the index of the char to remove * @param s the string to remove from * @return */ String removeNchar(int n, String s) { if (n>0 && n