I've been trying to code an anagram finder in Java so that in the terminal after compiling all I would have to do is
- Type in
java Anagramfind list.txt
- When prompted type in a word, say
treasure
- The program prints an anagram, like
austerer
- Another prompt comes up asking if I would like another one (
yes/no
)
The list.txt file has most, if not all, of the words in the English language.
Here's what I have so far...
import java.util.*;
import java.io.*;
class ProjectAnagram {
public static void main (String[] args throws IOException) {
//THis here declares an array of strings
Scanner dictionary = new Scanner new (fileInputStream(args[0]));
String[] entireArray = new String[173528]; //name of array + 173258
System.out.println ("Put something in please");
Scanner keyboard = new Scanner(System.in);
System.out.println ("Inserted");
String word = keyboard;
}
I still need to add the rest.
I've mostly been having trouble with the use of arrays, which I referenced here:
- Java read file and store text in an array
- http://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html
- What is "String args[]"? parameter in main method Java
I also am having trouble using a Stringbuffer which to check if words have the same characters or not.
The program checks if the input string and if the string in the text file have the same length first so as to rule out obvious non-anagrams. If it doesn't, then it moves on to the next word in the list, probably with i++
in some loop.