• Post Reply Bookmark Topic Watch Topic
  • New Topic

I want: Scan.findInLine(word).charAt(number); to scan a word, not a word written in the console.  RSS feed

 
Joseph Alrawi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I'm having an issue, I have a scanner (Scan.nextLine();) that scans the console for input to fetch the string "word". Then I want to fetch a character using Scan.findInLine(word).charAt(number);. The problem is that the console requires me to write 2 lines in order for the program to move on. I only want the program to scan for a word, and then move on with what it has instead of requiring 2 inputs. What should I do?

Thank you!
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, read javadoc of Scanner to see what those method does.
Why don't you use Scan.nextLine()?
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beware of nextLine(). It is not a good name and most of the books misunderstood how it works. There are more details in this post.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!