| | |
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 |
Tag cloud for Java
@param android animated api appinventor apple applet application arguments array arrays automation binary bluetooth c++ chat chatprogramusingobjects chooser class classes client code codesnippet compiler component coordinates database doctype draw eclipse editor error event exception file fractal freeze game givemetehcodez graphics gui guidancer health helpwithhomework html ide image input int integer j2me java javaprojects jmf jni jpanel jtable julia linux list login loop map method methods mobile netbeans newbie nonstatic number oracle page plazmic print problem program programming project recursion scanner screen sell server set sharepoint size sms socket sort sourcelabs sql string swing system test testautomation threads time tree windows





