wood burning stoves
The moose likes Beginning Java and the fly likes user input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "user input" Watch "user input" New topic

user input

Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
hey guys, long time since I been in here, but I am trying to get back into my java. I have not used it in a while.

I have a small question, which I have tried to look long and hard on the api for over 2 days and can't seem to find it.

I have a small program that I am trying to play around with.

what I am trying to do is, get some user input.

I am trying to get the user to input A,B or C but I just cannot find the command.

can anyone help?

I put this in the beginners section because I am classing myself as a beginner again, because it has been such a long time since I used java.


How simple does it have to be???
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276



Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Actually, you can wrap a BufferedReader around System.in (not System.out) to achieve this...

James Carman, President<br />Carman Consulting, Inc.
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Mark, that did not work at all.

James, your code of

worked, but I am having prob with just getting a char to be used, i have to declare as a String, but all I need is a char.

but I am having trouble getting a char, any help.

god, I learned this when it was 1.2/1.3 I need to get another book for 1.5, lots has changed.

here is my code to help you understand what I am trying to do:

[ April 11, 2005: Message edited by: Davy Kelly ]
Travis Zimmerman

Joined: Mar 06, 2002
Posts: 27

char y = input.readLine().charAt( 0 );
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

The problem here primarily is that you can't read a char from System.in as the key is pressed; you only receive them once "ENTER" has been hit.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
Thank you travis, that worked a treat.

And sorry about the code, I noticed it had a small flaw, that all were going to be fine, cause x always was going to be a, I did change that quickly.

thanks again all.

p.s. it is a pity this forum does not have reputation points, you would all get one.
I agree. Here's the link: http://aspose.com/file-tools
subject: user input
It's not a secret anymore!