Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

user input

 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.readln()?

Mark
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, you can wrap a BufferedReader around System.in (not System.out) to achieve this...

 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try

char y = input.readLine().charAt( 0 );
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic