• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

user input

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.readln()?

Mark
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try

char y = input.readLine().charAt( 0 );
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Can't .... do .... plaid .... So I did this tiny ad instead:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic