Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Taking interactive input from console  RSS feed

 
Manish Malik
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Most of the programs I have seen, which require user input, read it from the command line.
What is the method equivalent to C++'s cin or scanf(), so that user can interactively input values in a console Java program?
Is this method too tedious to implement that most programs resort to command line?

------------------
Manish.
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.in is the standard Java input stream. System.in.read() (or one of it's forms) might work for you.
Originally posted by Manish Malik:

Most of the programs I have seen, which require user input, read it from the command line.
What is the method equivalent to C++'s cin or scanf(), so that user can interactively input values in a console Java program?
Is this method too tedious to implement that most programs resort to command line?


 
Don Smathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at JOptionPane class of javax.swing.JOptionPane
It's a bit awkard, but it works for many cases.
Personally, I don't consider it a professional solution to input in Java, but then, from what I've read, Java was never intended to be a language for input; just output.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!