• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading from console  RSS feed

 
bob john
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have learned some code.
However I heard  " Reading data from console ". Cannot be sure, but possibly was mentioned 'input' and 'output'.
So I need to know that method (or whatever it is called) to be able to read text from console.


 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can read from the console like that. I think there are better ways to do it, but that method with a Scanner pointing to System.in will work. Beware of using the nextLine method after nextInt or next nythingElse.
Please separate the reading and writing into individual methods; they are separate tasks and shou‍ld not be grouped together. You must close anything pointing to a file, socket, etc; I think (if you use Java7+) the best way to do that is try with resources. Don't use that for System.in or System.out or System.err because you mustn't close those streams.
You can find out more about input and output in other parts of the Java™ Tutorials.
 
bob john
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About 21th and 23th line, yes I know. Just wrote as example.

You can find out more about input and output in other parts of the Java™ Tutorials.

Can you write me a code, that reads data from console? Because I have difficulties with that website. I usually find out how to code via forums or asking.
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 16 seems to be reading data from the console just fine.  Is there a problem with it?
 
bob john
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Line 16 seems to be reading data from the console just fine.  Is there a problem with it?

Works fine. Expected something more complex.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!