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
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.
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
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.
Scanner s= new Scanner(System.in); char aCharacter = s.next().charAt(0);
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.