Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Scanner searching for more than just one word

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

// If user input is "it's cold outside" instead of just "cold", the program moves (like it's supposed to do) to the else statement.  How do I get it to run and pick out keywords without knowing user input?


     


Thanks for the assist.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Marshal
Posts: 68909
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you been taught about what nextLine() does? You might do well to read the individual words with next() and tes‍t them for equality. Or you can use a switch if you prefer. Just beware of weather forecasts like this:-

It will be freezing cold until 10 o'clock, after which it will become very warm.

 
Joe Duncan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.  From my research, I have found nextLine() will read spaces and next() will not. Good call on the weather forecasts.  That never crossed my mind.  
 
Campbell Ritchie
Marshal
Posts: 68909
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have missed the crucial problem with nextLine(), I am afraid.
 
Joe Duncan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back to the research!  Thanks
 
Campbell Ritchie
Marshal
Posts: 68909
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Duncan wrote:. . . . Good call on the weather forecasts. . . .

That suggests you haven't lived in Britain, where weather forecasts have to cover all possibilities on spec.
 
Campbell Ritchie
Marshal
Posts: 68909
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Joe Duncan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

// If user input is "it's cold outside" instead of just "cold", the program moves (like it's supposed to do) to the else statement.  How do I get it to run and pick out keywords without knowing user input?


     


Thanks for the assist.
 
today's feeble attempt to support the empire
Learn to write code others love to read, one example at a time!
java.by-comparison.com
    Bookmark Topic Watch Topic
  • New Topic