Solved

String to char (keyboard entry problem)

Posted on 2004-05-02
4
834 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 50
jdbc error in jsp application 20 44
servlet web applications   metadata-complete="true" or false 3 37
jboss wildfly 10.1 10 76
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

813 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

15 Experts available now in Live!

Get 1:1 Help Now