Here's my current code that I'm using:
What it does is it actively writes the results to a file on my Desktop called test.txt.
I current have 3 for loops set on it, which by the dumb principles on my programming, means a 3 char limit.
Expand|Select|Wrap|Line Numbers
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStreamWriter;
- public class Generate {
- public static void Gen() throws IOException
- {
- //opens a file writing stream
- FileOutputStream fos = new FileOutputStream("C:\\Users\\Ryan\\Desktop\\test.txt");
- OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8");
- //the character list I'm using
- String CharList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- //gets a list of characters
- String[] CharSplit = CharList.split("");
- String Str = "";
- //generates text document on my desktop of possible combinations
- //only currently a max length of 3 since I have no idea how to simulate more for loops or what not
- //notice that 3 for loops = char length of 3
- for(int I = 1;I<CharSplit.length;I++)
- {
- //takes up first character
- Str += CharSplit[i];
- //writes it to a file, along with a separation to the next line
- out.write(Str + System.getProperty("line.separator"));
- //clears Str for further use
- Str = "";
- for(int O = 1;O<CharSplit.length;O++)
- {
- //writes 2 pieces into Str for a 2 char length
- Str += CharSplit[i] + CharSplit[O];
- //writes to file along with a new line
- out.write(Str + System.getProperty("line.separator"));
- //clears Str
- Str = "";
- for(int P = 1;P<CharSplit.length;P++)
- {
- //writes 3 pieces into Str for a 3 char length
- Str += CharSplit[i] + CharSplit[O] + CharSplit[P];
- //writes to file along with new line
- out.write(Str + System.getProperty("line.separator"));
- //clears Str
- Str = "";
- }
- }
- }
- //closes the file writing stream
- out.close();
- }
- }
- /*
- How can I simplify the for loops so that they are more customizable?
- Ex:
- A variable called Length controls the maximum length, no need to paste in new for loops
- */