| | |
Contains() / Anagram Question
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
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?
![]() |
Similar Threads
- C command-line I/O question (C++)
- Anagram Tester Program That I Just Can't Figure Out (Computer Science)
- Apache Alias Directive... mod_alias question (Linux Servers and Apache)
- Completely new to C++ and have question about using char (C++)
- Question (Geeks' Lounge)
- question on cooling (Cases, Fans and Power Supplies)
- Context-sensitive grammar question :( (Computer Science)
- Welcome PC Mod Kingdom peeps! (Geeks' Lounge)
- Laptop LCD built into a car? (Monitors, Displays and Video Cards)
- Changing Network Configuration (*nix Software)
Other Threads in the Java Forum
- Previous Thread: one more ArrayList Question...
- Next Thread: web audio stream and jmf
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time title tree tutorial-sample ubuntu update windows working





