I created a program To return if a String entry is equal to "password". Sort of a password program. As you can see from the output the entry and expression are both equal. Why then does it print wrong??
package Main;
import java.io.*;
class password
{
public void password() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the password");
String entry = br.readLine();
System.out.println("printing the entry: " +entry);
String password = "abc";
if (entry== password)System.out.println("Correct");
else System.out.println("Not a match");
}
}
output:
enter the password
>abc
printing the entry: abc
Not a match
Please rectify the program and suggest a better method of doing it