PuffyCloud 0 Newbie Poster
import java.io.*;
import java.util.Scanner;
public class pa4 {
  public static void main (String[] args) {
    int i;
    boolean loop = false;
    
    do {
      Scanner inFromFile = null;
      try {
        inFromFile = new Scanner(new FileInputStream("words"));
      }
      catch (FileNotFoundException e) {
        System.out.println ("Could not open the file");
        System.exit (0);
      }
      Scanner in = new Scanner(System.in);
      String s;
      String x;
      
      System.out.println("Enter some text. To quit, simply type a period.");
      s = in.nextLine();
      s = s.toLowerCase();
      if (s.equals(".")) loop = true;
      else {
        while (inFromFile.hasNext()) {
          x = inFromFile.next();
          if (s.contains(x)) System.out.println(x);
        }
      }
    } while (!loop);
  }
}

My code is for the purpose of running through a wordlist and seeing what words it can make from the user input.

The problem I'm running into is if, say, the user types in "ball" the program will output "a", "all", and "ball" but will skip over words like "lab" because it's not in order in the world "ball".

I'm confused as to how I can solve this problem can anyone offer advice?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.