所以我有一个非常基本的登录程序,当您输入正确的凭据时,它只会打印一行。即使我输入正确的凭据,它所做的只是从我的 if else 语句中打印错误消息。任何帮助将不胜感激。
import java.util.Scanner;
public class Exercise4
{
private static String Username = "javacave";
private static String Password = "welcome1";
public static void main(String[] args)
{
System.out.println("Please enter username");
Scanner in = new Scanner(System.in);
String UN = in.nextLine();
System.out.println("Please enter password");
Scanner inn = new Scanner(System.in);
String PW = inn.nextLine();
if (UN == Username && PW == Password)
{
System.out.println("User has logged in successfully!");
}
else {
System.out.println("You have entered the wrong credentials, please try again.");
}
}
}