Results 1 to 5 of 5
Thread: How to read a Char character ?!
- 03-27-2010, 03:24 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 15
- Rep Power
- 0
-
I don't think you can, not in the way that you are trying (though I could be wrong). To really do this well, you may want to create a Swing GUI and add a DocumentListener to a JTextField.
- 03-27-2010, 03:30 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 15
- Rep Power
- 0
mmm .. got no idea of what u proposed ..
anyway, thanks a lot dude !
- 03-27-2010, 03:57 PM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Java Code:Scanner s = new Scanner(System.in); char a = s.next().charAt(0);
- 03-27-2010, 06:01 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
A Scanner is way too 'sophisticated' for reading single chars; better use the wrapped Readers for those simple tasks but if you really want to read a single char with a Scanner you can do it like this:
Only one char will be read from the input, the rest of the characters will be left in the associated streams.Java Code:char chr= scanner.next(Pattern.compile(".")).charAt(0);
kind regards,
Jos
Similar Threads
-
Read a single character entered
By mcmb03 in forum New To JavaReplies: 2Last Post: 01-31-2010, 10:30 PM -
How to read a letter instead of a character from a given sentences
By lclclc in forum New To JavaReplies: 8Last Post: 09-15-2009, 11:53 AM -
read char words lines
By Drukqs in forum New To JavaReplies: 6Last Post: 05-14-2009, 06:14 PM -
Read from a certain character to a certain character
By blackstormattack in forum New To JavaReplies: 0Last Post: 03-16-2009, 11:36 AM -
Char type for first character typed?
By Sageinquisitor in forum New To JavaReplies: 3Last Post: 07-17-2007, 07:08 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks