File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How to feed Input from keyboard? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to feed Input from keyboard?" Watch "How to feed Input from keyboard?" New topic

How to feed Input from keyboard?

Saptaparna Dhar

Joined: Sep 16, 2011
Posts: 10
I am trying out simple programs like-- to find GCD etc. Can you please tell me how can a user feed input from keyboard in command prompt/in java.I have searched in google,but could not understand properly.It being my first day of programming in java,I am not getting how to use KeyboardReader or Scanner class.Which package do I need to import to work with either of these?
Please suggest an easy way to feed the input data
Philip Thamaravelil
Ranch Hand

Joined: Feb 09, 2006
Posts: 99
You have a java program you are running on the command line correct? And you want to read user input from the command line?

Here's an example if that's your question:
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

Creating a java.util.Scanner around will also work, and if you run your program from an actual command line (not an IDE) you can also use System.console().

How To Ask Questions How To Answer Questions
Saptaparna Dhar

Joined: Sep 16, 2011
Posts: 10
Thank you both.
My problem is solved and I found the tips to be really useful.I know these are the most basic things in Java.But for a child, alphabet series appears to be the most difficult thing invented.So is in my case.
Thank you again.
I agree. Here's the link:
subject: How to feed Input from keyboard?
It's not a secret anymore!