2 Replies - 7108 Views - Last Post: 18 October 2009 - 01:31 PM Rate Topic: -----

#1 zachjjones  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 28-March 09

how to store the user input into a string

Post icon  Posted 18 October 2009 - 01:22 PM

I want to store the word the user keys in from System.in into a string. Then I want to use that string to find any matches in an xml document. I also get an error on the myMap line of code. It can't be resolved. Is myMap not supposed to go there?

if((vocWord).matches(word.substring(0, word.length()-1) + "\\w+")) 
System.out.println("Found prefix: " + word + "\t" + (myMap.get("def")) );

if(vocWord.matches("\\w+" + word + "\\w+") || vocWord.matches("\\w+" + word) 
|| vocWord.matches( word + "\\w+")) System.out.println("Found root: " + word + "\t" 
+ myMap.get("def"));


I tried making Scanner scan = new Scanner(System.in) = String vocWord;

But that can't be done. What can I do to store the word the user inputs into the string vocWord?

Is This A Good Question/Topic? 0
  • +

Replies To: how to store the user input into a string

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: how to store the user input into a string

Posted 18 October 2009 - 01:26 PM

Scanner scan = new Scanner(System.in);

String userInput = scan.nextLine();


:)
Was This Post Helpful? 1
  • +
  • -

#3 zachjjones  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 28-March 09

Re: how to store the user input into a string

Posted 18 October 2009 - 01:31 PM

One line of code is all it takes. Thanks!

I still don't know what to do about the map. I'm confused as to what is going on there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1