0
올바른 로그인 정보를 입력 할 때 줄을 인쇄하는 매우 기본적인 로그인 프로그램이 있습니다. 올바른 신임장을 입력하더라도 내 if else 문에서 오류 메시지가 인쇄됩니다. 어떤 도움이라도 대단히 감사하겠습니다.사용자 입력이있는 명령 줄을 통한 기본 로그인 java가 작동하지 않습니다.
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.");
}
}
}
그리고 이것은 자바 클래스에서 배우는 핵심 기능이어야합니다. 문자열 라이브러리에서 읽어야합니다. 프로젝트에 행운을 빈다. ;) –
대단히 감사합니다. 게시하기 직전에 알아 냈습니다. –
"두 문자열 사이를 비교할 때마다"라는 말은 실제로 "두 개체간에 비교할 때"가되어야합니다. 이것은 원시 타입이 아닌 모든 것에 적용됩니다. == 참조를 비교하고, .equals()가 오버로드되어 값을 비교할 수 있습니다. –