This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes user input values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
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: 17
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: 37890
    
  22
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: 61

The only interesting thing is....

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


SCJP-6.0 OCPJWCD-5.0
Vidyakar Sharma
Greenhorn

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

Joined: Oct 13, 2005
Posts: 37890
    
  22
Remember that Console only works when you start the application from the command line with the java command.
 
Consider Paul's rocket mass heater.
 
subject: user input values
 
Similar Threads
Preserve input values when validation fails!
Taking interactive input from console
Help code problem please
System.in.read()
Can Someone Help with Reading from a text file in J2ME