aspose file tools*
The moose likes Beginning Java and the fly likes BufferedReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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: 3739
    
  16
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: 690
    
    1
a method used to read in a single character?


Look at the API doc for InputStreamReader read() method.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: BufferedReader