Results 1 to 3 of 3
  1. #1
    mcmb03 is offline Member
    Join Date
    Jan 2010
    Rep Power

    Post Read a single character entered

    Hi, I've only been doing java for a few days now so cut me a little slack :)

    I'm making a "guess the random number" game and at the end I want to have the user input if they'd like to play again with a simple 'y' / 'Y' or 'n' / 'N'

    If I could just be told at least how to input a character and then read it's ascii code I can figure it out. Thanks!

  2. #2
    tim's Avatar
    tim is offline Senior Member
    Join Date
    Dec 2007
    Rep Power


    Hi there.

    This code will read and print a single character. The BufferedReader class has some more methods you might find interesting, including readLine().
    Java Code:
    public class Main {
    	public static void main(String[] args) {
    	public static char readCharacter() {
    		try {
    			BufferedReader reader = new BufferedReader(new InputStreamReader(;
    			return (char);
    		} catch (Exception e) {
    		return 0;
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    mcmb03 is offline Member
    Join Date
    Jan 2010
    Rep Power

Similar Threads

  1. Replies: 8
    Last Post: 09-15-2009, 11:53 AM
  2. Read from a certain character to a certain character
    By blackstormattack in forum New To Java
    Replies: 0
    Last Post: 03-16-2009, 12:36 PM
  3. Read character from Image area
    By sundarjothi in forum Advanced Java
    Replies: 2
    Last Post: 01-12-2009, 06:00 AM
  4. Replies: 5
    Last Post: 11-22-2008, 02:34 PM
  5. how to read single Keystroke without using return
    By oomanamemni in forum New To Java
    Replies: 1
    Last Post: 02-14-2008, 08:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts