我正在編寫一個方法來搜索列表形式的單詞文本文件,對於由用戶輸入但由程序輸入的單詞將返回肯定的結果,如果一個字母在所有被發現,例如,如果我搜索「F」,它將返回有在字典中的單詞「F」時,有沒有正在搜索一個文本文件
public static void Option3Method(String dictionary) throws IOException {
Scanner scan = new Scanner(new File("wordlist.txt"));
String s;
String words[] = new String[500];
String word = JOptionPane.showInputDialog("Enter a word to search for");
while (scan.hasNextLine()) {
s = scan.nextLine();
int indexfound = s.indexOf(word);
if (indexfound > -1) {
JOptionPane.showMessageDialog(null, "Word was found");
} else if (indexfound < -1) {
JOptionPane.showMessageDialog(null, "Word was not found");
}
}
}