This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "user input" Watch "user input" New topic
Author

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.

Davy


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

Joined: Feb 05, 2001
Posts: 17250
    
    6

System.out.readln()?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
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:


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

Joined: Mar 06, 2002
Posts: 27
Try

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

Joined: Aug 20, 2001
Posts: 1817

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.

Davy
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