Solved

String to char (keyboard entry problem)

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 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

21 Experts available now in Live!

Get 1:1 Help Now