Okay so the question is to read in the file and search through it and be able to find words with the letters you entered so for example I enter A??C all the words in the dictionary with A as the first letter and C as the fourth letter would be returned. It is supposed to be used to help solve crosswords
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
NewClass reader = new NewClass();
String[] contents = reader.load("/home/se211012/CS211/text");
Scanner scan = new Scanner(System.in);
System.out.println("enter word");
String s = scan.nextLine();
for (int i = 0; i < contents.length; i++) {
}
}
}
Reading in the file is fine I have a class that does that as you can see, but I don’t know where to go from here. Any help would be appreciated.
You should probably use a regular expression to achieve it.
Create your regex to match the words, and search for a match through the collection.
Note that in regular expressions,
.means any character.You might want to hava a look on the Matcher and Pattern classes as well.