It's not a secret anymore!
The moose likes Beginning Java and the fly likes BufferedReader Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "BufferedReader" Watch "BufferedReader" New topic
Author

BufferedReader

Ayo Ayo
Greenhorn

Joined: Sep 05, 2005
Posts: 3
Hello all,

I am trying to write a program that prompts the user to enter a single character e.g 'Y'. The problem is that when I try to read it using the BufferedReader Object: readLine() method and do some comparism with another char variable, it gives me the wrong result, ie always 'No' No matter the input. Does anybody know of a method used to read in a single character?

My code is as follows;

String InData;
String intData1 = "Y"';
BufferedReader dataString =
new BufferedReader (new InputStreamReader(System.in));
System.out.println("Would you like pin strip (�250.00) Y/N"); InData=dataString.readLine();

if(InData1=='InData')
{
System.out.println("ok");
}
else
{
System.out.println("No");
}

THANKS


If your way is easy, you are definitely on the wrong way
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3011
    
    9
Use String.equals() to compare strings, not ==.


Joanne
Ayo Ayo
Greenhorn

Joined: Sep 05, 2005
Posts: 3
Thanks a lot Joanne Neal.

Ayo Ayo
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 681
a method used to read in a single character?


Look at the API doc for InputStreamReader read() method.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: BufferedReader
 
Similar Threads
parse to double required? variable declarations
Input Output If
HELP! Why not Compiling ? Easy but.......
readLine() and read() functionality
input