Topics: Lower case, Punctuation, Programming language Pages: 3 (448 words) Published: April 6, 2013
import java.util.*;

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(;

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 =;
//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 =;
String tempWord2 = stripPunc(tempWord.toLowerCase()); createSig(tempWord2, n);


//Calls the 'sortBoth' method.

//Goes through each element in 'sigList' and...
Continue Reading

Please join StudyMode to read the full document

Become a StudyMode Member

Sign Up - It's Free