I'm writing a method to search a text file of words in list form, for a word that is entered by the user but by program will return a positive result if one letter is at all is found e.g, if i search "f" it will return that there's is a word "F" in the dictionary when there isn't
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"); } } }