tags:

views:

168

answers:

2

How do i read a char from a user in the command line. I am familiar wit readInt() is there some thing like this for chars.

please help this is for the stanford course i am taking online as part of stanford engineering everywhere over the summer and i need to finish soon before my high school term starts.


Is there any way I can do this using the acm.util acm.program acm.util or java.awt class because that's all i'm allowed for the assignment

+7  A: 
final DataInputStream dis = new DataInputStream(System.in);
final char c = dis.readChar();
Mike
+5  A: 

The java.util.Scanner class was pretty much built for this :), but oddly remains something of a hidden secret as not many people know about it.

Chris Kessel
I remember when I was teaching Java during Grad School, the text book mentioned the scanner class and I had to quickly go look it up before class to make sure I knew it - I had never heard of it before then. +1 for obscure knowledge :)
aperkins
@aperkins: The Scanner class didn't come around until Java 5 and didn't seem as heavily advertised as some of its other features.
R. Bemrose
JDK 1.5 has only been out for, what, 4 years? :)
Chris Kessel
Yeah, but "read from the command line" is something you usually don't return to after learning it in Java 101. :-) +2 for this answer if I could give it.
Dean J