我目前有一個登錄系統,只需要登錄號碼。這意味着用戶名,密碼和學生號碼(全部需要登錄)都只是數字。我正在尋找一種方法將用戶名和密碼更改爲單詞而不是數字。我將如何做到這一點?我嘗試過使用字符串,但無法從控制檯接受輸入。這是我的代碼;在整個登錄系統中將整數更改爲字符串
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
final int UserID = 5555;
final int Password = 1234;
final int StudentNumber = 22334455;
int EnteredUserID;
int EnteredPassword;
int EnteredStudentNumber;
for (int s = 0; s <= 3; s++) {
if (s < 3) {
System.out.println("Enter your UserID to access lift;");
EnteredUserID = console.nextInt();
System.out.println("Your UserID is >>> " + EnteredUserID);
System.out.println("Enter your password to authenticate login;");
EnteredPassword = console.nextInt();
System.out.println("Password Entered is >>> " + EnteredPassword);
System.out.println("Enter your student number to finalise login and authentication;");
EnteredStudentNumber = console.nextInt();
System.out.println("Student Number Entered is >>> " + EnteredStudentNumber);
if (UserID == EnteredUserID && (Password == EnteredPassword)
&& (StudentNumber == EnteredStudentNumber)) {
System.out.println("Athentication complete!");
System.out.println("***Elevator access granted!***");
System.out.println("Welcome...");
Elevator a = new Elevator();
Elevator.selectFloor();
break;
} else {
System.out.println("Wrong UserID, Password or Student Number. Please try again.");
}
} else {
System.out.println("3 incorrect enteries detected. Access Denied!");
}
}
}
我試圖改變爲字符串的用戶名和密碼,並使用console.nextLine()
和console.next()
,但既不似乎工作和存儲輸入的內容。
您是否還記得在比較「字符串」時將'=='更改爲'equals'? – ajb
不要將'String'與'=='進行比較。你需要使用'equals()'。 – GriffeyDog
您是否將nextInt()更改爲next或nextLine()? –