Question: I need help with removing duplicate permutations in java. It is very important that there is no usage of SETS or any other implementation of
I need help with removing duplicate permutations in java. It is very important that there is no usage of SETS or any other implementation of SETS!
What I have so far.
package permutation;
import java.io.*; // needed for File, FileReader, and BufferedReader classes import java.util.ArrayList; import java.util.Iterator; import java.util.Scanner;
/** * * @author kevin */
public class permutationsconsole { private static ArrayList createDictionary() throws FileNotFoundException { FileReader dictionary = new FileReader("wordsEn.txt"); BufferedReader reader = new BufferedReader(dictionary); ArrayList
writer.close();
} private void writeStringToFile(String data) throws IOException { FileWriter writer = new FileWriter("/yourpath/to/output.txt", true); // this needs to be corrected as well. writer.write(data); writer.write(" "); writer.close(); } public static void main(String args[]) throws FileNotFoundException { File output = new File("perms.dat"); // file that will hold the permutations ArrayList dictionary = createDictionary(); // the ArrayList that is returned by this method is stored in a new ArrayList. Scanner kbd = new Scanner(System.in); boolean isDone = false; do { System.out.println("Type in a word and this program will calculate its permutations."); String word = kbd.nextLine(); for(int i = 0; i < 1; i++) { permutationscalculator pc = new permutationscalculator(word); } System.out.println("Would you like to continue?(y/n)"); char quit = kbd.nextLine().charAt(0); if(quit == 'y') { isDone = true; } else { isDone = false; } }while(isDone == true); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
