aspose file tools*
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
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: 39436
    
  28
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: 39436
    
  28
Remember that Console only works when you start the application from the command line with the java command.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: user input values