File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes user input values Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "user input values" Watch "user input values" New topic
Author

user input values

tushar parab
Greenhorn

Joined: Feb 11, 2009
Posts: 5
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

Joined: Dec 27, 2009
Posts: 16
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.


Vidyakar Sharma.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 25060
You can also use Swing classes, eg the input dialogue method of JOptionPane.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Or you can use the java.io.Console class as of java 6


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Anupam Jain
Ranch Hand

Joined: Mar 16, 2010
Posts: 60

The only interesting thing is....

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


IMPOSSIBLE == I M POSSIBLE --> true
SCJP 6.0 (does that mean I know JAVA...? mmm really doubtful... )
Vidyakar Sharma
Greenhorn

Joined: Dec 27, 2009
Posts: 16
Hey Anupam,
You are forgetting that Scanner has a number of methods like nextInt and nextLong.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 25060
Remember that Console only works when you start the application from the command line with the java command.
 
 
subject: user input values
 
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com