String Compare not working
Hi all, sorry for simplicity of this question but its bugging me and I'm just frustrated now. Java and how their strings work in IF statements confuses me a little. They don't behave like C++.
basically I have a function that looks like
Code:
String option = read_input();
System.out.println(option);
if(option.compareTo("y") == 1)
{
do thing 1
}
else
{
do thing 2
}
my read_input function looks like
Code:
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader(isr);
output = stdin.readLine();
return output;
So, when I press "y" it does thing 2. I want thing 1 dang it! So, I must be doing something fundamentally incorrect here. Is my string compare wrong.
I repeat the function a little later in the program to enter number of days.
Code:
String select_days = read_input();
int num_days = Integer.parseInt(select_days.toString());
and when I enter
50
It throws a number exception at me.
What am I doing wrong?
Thanks,
James