public class anagram {
//Creates the arrayList called 'wordList' that is used to store the words from the file. private static ArrayList wordList = new ArrayList(); //Declares an array of String type called 'sigList'. static String[] sigList; //Creates the scanner that is used to read the input file private static Scanner scanner = new Scanner(System.in);
public static void main(String args[]) throws IOException { //Prompts the user for an input file. If the file exists, //it then begins to go through each word in the file. System.out.print("Enter the name of the input file: "); String fileName = scanner.nextLine(); File file = new File(fileName); try { Scanner sc = new Scanner(file); String s; while (sc.hasNext()) { s = sc.next(); //The program must tests the number of character per word. //If a word consist of more than 12 characters, the program ignores it and continues. if (s.length() 50) { System.out.println("there are more than 50 words in the input file"); System.exit(1); }
//Sets the length of 'sigList' as the same size as 'wordList'. sigList = new String[wordList.size()];
// the program treats upper and lower case letters as equivalent and ignore punctuation marks. //However, the program displays word with their original capitalizations and punctuations. ListIterator i = wordList.listIterator(); int n = 0; while (i.hasNext()) { String tempWord = i.next(); String tempWord2 = stripPunc(tempWord.toLowerCase()); createSig(tempWord2, n); n++;
}
//Calls the 'sortBoth' method. sortBoth();
//Goes through each element in 'sigList'