• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Scanner searching for more than just one word

 
Greenhorn
Posts: 13
  • 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: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Marshal
Posts: 69411
276
  • 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: 13
  • 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: 69411
276
  • 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: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back to the research!  Thanks
 
Campbell Ritchie
Marshal
Posts: 69411
276
  • 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: 69411
276
  • 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: 13
  • 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.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic