import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * * This program helps to find the WORDL word of the day. * It cycles through the dictionary of 5 letter words and applies various conditions * to help narrow the word down. * * * @author Dave Slemon */ public class Main { public static void main(String args[]) throws FileNotFoundException { String a_word; char[] c; boolean found=false; //creating File instance to reference text file in Java File text = new File("words.txt"); //Creating Scanner instance to read File in Java Scanner scnr = new Scanner(text); //Reading each line of the file using Scanner class int lineNumber = 0; while(scnr.hasNextLine()){ a_word = scnr.nextLine().toUpperCase(); if (a_word.length() != 5) continue; c = a_word.toCharArray(); //the WORDL word HAS these letters in the right position //if (c[0] != 'I' ) continue; //if (c[1] != 'E' ) continue; //if (c[2] != 'A' ) continue; //if (c[3] != 'A' ) continue; if (c[4] != 'E' ) continue; //the WORDL word HAS these letters but position is unknown if (!a_word.contains("N")) continue; if (!a_word.contains("R")) continue; if (!a_word.contains("S")) continue; //these letter CAN NOT appear in these positions if (c[0] == 'N') continue; if (c[2] == 'R') continue; if (c[3] == 'S') continue; //these letters DO NOT APPEAR ANYWHERE found = false; for(char x : c) { if ( //x == 'A' || x == 'U' || x == 'D' || x == 'I' || x == 'O' || x == 'C' || //x == 'R' || x == 'Y' || x == 'P' || x == 'T' || x == 'B' || //x == 'E' || x == 'V' || //x == 'E' || x == 'L' || x == 'W' || x == 'I' || //x == 'N' || x == 'K' || //x == 'S' || x == 'K' ) { found=true; break; } } if (found) continue; System.out.println(a_word); lineNumber++; } System.out.println("count = "+ lineNumber); } }