I do realize that this is ugly code but i cant seem to have this program output "Your old". I dont know why my if statement is not working.

Thanks

/*
This class is to be used as new readline method
*/
import java.io.*;
class ReadInput
{
public static void main(String[] args)
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(reader);

ReadInput r = new ReadInput();
try{
r.readline(in);
}
catch (IOException e)
{
System.out.print("\n Exception caught \n");
}

}

public void readline(BufferedReader b)throws IOException
{
String input ="sixty";
//Buffer is empty at the moment
while(true)
{
System.out.print("Please enter your age: ");
input = b.readLine();
// else
System.out.println(input);
if (input == "sixty")
{
System.out.println("Your old");
}
else
{
System.out.println("eh");
}
}
}
}

You can't use the == operator on a string comparison in java. You need to call the equals method like so:

if(input.equals("sixty"))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.