Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: character reading

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    57
    My Mood
    Fine
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default character reading

    i am using jdk 6 ... i came to know that how we can read strings from user input ... and how we can convert a string to int .. but i dont fount how to read a character by character from user .. kindly specify with full syntax
    thanks


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: character reading

    Quote Originally Posted by deependeroracle View Post
    i am using jdk 6 ... i came to know that how we can read strings from user input ... and how we can convert a string to int .. but i dont fount how to read a character by character from user .. kindly specify with full syntax
    thanks
    READ THE FORUMS RULES.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: character reading

    Look at the Scanner class for reading input from a user.

  4. #4
    Junior Member
    Join Date
    Sep 2014
    Location
    Chandler, AZ
    Posts
    1
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: character reading

    Quote Originally Posted by Norm View Post
    Look at the Scanner class for reading input from a user.
    Looking at the scanner class it still doesn't seem obvious to me...

    reading java for dummies i did find the following:

    Scanner keyboard = new Scanner("System.in");
    char reply;
    reply = keyboard.findWithinHorizon(".", 0).charAt(0);

    So it's in there as you suggested just not easy to find for a newbie like me.

  5. #5
    Member
    Join Date
    Aug 2013
    Posts
    205
    My Mood
    Amazed
    Thanks
    5
    Thanked 40 Times in 39 Posts

    Default Re: character reading

    Scanner s= new Scanner(System.in);
    char aCharacter = s.next().charAt(0);

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,952
    Thanks
    56
    Thanked 2,353 Times in 2,324 Posts

    Default Re: character reading

    The findWithinHorizon() method uses regular expressions which are more complicated than other methods like next() or nextLine().
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. character problem
    By prettynew in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 4th, 2011, 11:58 AM
  2. [SOLVED] Illegal character
    By Tank314 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 12th, 2011, 11:59 AM
  3. Character Array
    By p_dibb in forum Collections and Generics
    Replies: 1
    Last Post: February 16th, 2011, 10:08 AM
  4. How To Retain Entity Reference Character While Reading XML
    By leon850515 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 2nd, 2011, 09:10 AM
  5. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 12:13 PM