?
Solved

String to char (keyboard entry problem)

Posted on 2004-05-02
4
Medium Priority
?
838 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 16

Expert Comment

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

Accepted Solution

by:
maheshexp earned 750 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

741 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