• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

User input from console

 
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am implementing a project and a small of that project is accepting input from user through command line. I have written the following code to do that


The problem i am facing is that the user has to press Enter twice to send the input. As you all can see, i have even tried to do the same thing using Scanner class. Can you guys suggest me what i am missing.

 
Marshal
Posts: 79837
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using the flush() method? That isn't usually necessary. I have never used it; don't know whether that is your problem.

I can't see anything else which would require two "enters". Sorry.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you tried to remove System.out.flush();
then run the program again?

Ryan Webb
Philippines
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, i tried doing that as well.
 
Campbell Ritchie
Marshal
Posts: 79837
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still can't see anything which requires double enter. Is there any more code?
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the entire class that i wrote. This is part of an Instant Messenger project. The run method of this class doesnt run in a separate thread. It is a plain Method. It is called from some other class. I basically tried quite a few things like:

Using Flush/ Without using Flush
Using Scanner Class/Without using scanner class

The snippet that i posted above is from the doChat() method.

 
Campbell Ritchie
Marshal
Posts: 79837
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your posted code is too long to read, and does not appear to contain the two flush() calls you originally posted.
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic