This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader

 
Ayo Ayo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use String.equals() to compare strings, not ==.
 
Ayo Ayo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Joanne Neal.

Ayo Ayo
 
Norm Radder
Ranch Hand
Posts: 892
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a method used to read in a single character?


Look at the API doc for InputStreamReader read() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic