我目前有一个登录系统,只需要登录号码。这意味着用户名,密码和学生号码(全部需要登录)都只是数字。我正在寻找一种方法将用户名和密码更改为单词而不是数字。我将如何做到这一点?我尝试过使用字符串,但无法从控制台接受输入。这是我的代码;在整个登录系统中将整数更改为字符串
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()? –