Solved

String to char (keyboard entry problem)

Posted on 2004-05-02
4
832 Views
Last Modified: 2010-04-16
Taking three pieces of information from the keyboard

first is of String : No Problem here
secons is of Int : No problem here.

Third is of char: The problem

Using the BufferedReader.readline or BufferedReader.read() methods  
I keep getting a 'Cannot convert String to Char error' on compilation.

What method should i use to read this character ?
 I see lots of examples of charAt().. But this is not the case. I am assuming that the user will enter either M or F
Exceptions can be dealt with later.

So how is the first character 'char' read in from the keyboard.
0
Comment
Question by:pbehan
4 Comments
 
LVL 16

Expert Comment

by:krakatoa
ID: 10971391
String.toCharArray();
0
 
LVL 7

Accepted Solution

by:
maheshexp earned 250 total points
ID: 10971650
char c = (char)System.in.read();
0
 
LVL 92

Expert Comment

by:objects
ID: 10974020
> So how is the first character 'char' read in from the keyboard.

the user still needs to enter carriage return, so you still need to do a readLine().

char c = in.readLine().charAt(0);
0
 
LVL 16

Expert Comment

by:gnoon
ID: 10974710
char ch = (char) buffreader.read(); // you can

but

char ch = (char) buffreader.readLine(); // you cann't
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now