Contains() / Anagram Question

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2009
Posts: 1
Reputation: PuffyCloud is an unknown quantity at this point 
Solved Threads: 0
PuffyCloud PuffyCloud is offline Offline
Newbie Poster

Contains() / Anagram Question

 
0
  #1
21 Days Ago
  1. import java.io.*;
  2. import java.util.Scanner;
  3. public class pa4 {
  4. public static void main (String[] args) {
  5. int i;
  6. boolean loop = false;
  7.  
  8. do {
  9. Scanner inFromFile = null;
  10. try {
  11. inFromFile = new Scanner(new FileInputStream("words"));
  12. }
  13. catch (FileNotFoundException e) {
  14. System.out.println ("Could not open the file");
  15. System.exit (0);
  16. }
  17. Scanner in = new Scanner(System.in);
  18. String s;
  19. String x;
  20.  
  21. System.out.println("Enter some text. To quit, simply type a period.");
  22. s = in.nextLine();
  23. s = s.toLowerCase();
  24. if (s.equals(".")) loop = true;
  25. else {
  26. while (inFromFile.hasNext()) {
  27. x = inFromFile.next();
  28. if (s.contains(x)) System.out.println(x);
  29. }
  30. }
  31. } while (!loop);
  32. }
  33. }

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?
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC