I think the first thing you need to do is consider how you will read the lines of input from the user and where to store those words? The below code should give you a start, it stores the words in an ArrayList of Strings and reads words from the console using a Scanner object. Change the name of the dictionary file to whatever it is on your system and also to signal the end of input after you have typed several words, press CTRL + D.
Code:
import java.util.*;
import java.io.*;
public class SubWords {
public static void main(String[] args) throws IOException {
Scanner console = new Scanner(System.in);
ArrayList<String> words = new ArrayList<String>();
System.out.println("Type each word followed by Enter: ");
while(console.hasNext()) {
words.add(console.next());
}
System.out.println();
System.out.println(countSubs(words));
}
public static int countSubs(ArrayList<String> words) throws IOException {
int count = 0;
File f = new File("dictionary.txt");
for(String eachWord: words) {
Scanner reader = new Scanner(f);
while(reader.hasNext()) {
String dictWord = reader.next();
if(dictWord.length() >= 3 && dictWord.length() < eachWord.length()) {
if(eachWord.contains(dictWord)) {
count ++;
}
}
else {
if(reader.hasNext()) {
reader.next();
}
}
}
}
return count;
}
}