So, I’m trying to make a simple scanner password where you input the password and if written correctly it should print out a message
If you input the correct password the code should print a message. But for some reason when I input the correct password it just commits to the else line. And yes I’ve tried the correct password multiple times even with the quotation marks included even though I doubted that.
import java.util.Scanner;
public class newtest {
public static void main(String[]args ) {
Scanner myObj = new Scanner(System.in);
System.out.println("Enter password");
String Pass = "Password123";
String password = myObj.nextLine();
if (password == Pass) {
System.out.println("Correct!! Password is: " + password);
}else
System.out.println("WRONG");
}
}
EBJ EBJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.