Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

user input values

 
tushar parab
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to take user input values in java as we do it in c by using scanf and in C++ using cin >>
 
Vidyakar Sharma
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi tushar,
use java.util.Scanner class for taking user inputs or
use Reader class with some buffering capability.
First one is easy for you as you are learning right now.
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use Swing classes, eg the input dialogue method of JOptionPane.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can use the java.io.Console class as of java 6
 
Anupam Jain
Ranch Hand
Posts: 61
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only interesting thing is....

All the above three input methods would give you String values only... (or so do I think.)

 
Vidyakar Sharma
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Anupam,
You are forgetting that Scanner has a number of methods like nextInt and nextLong.
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that Console only works when you start the application from the command line with the java command.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic