?? login.java
字號:
import javax.swing.JOptionPane;
public class Login {
public static void main(String[] args) {
String[][] user = new String[3][];//定義字符串數組,并且同一維為一組用戶名和密碼
user[0] = new String[] { new String("zhangxun"), new String("zx0808") };
user[1] = new String[] { new String("machao"), new String("mc0404") };
user[2] = new String[] { new String("humurong"), new String("hm0202")};
String users = JOptionPane.showInputDialog("請輸入用戶名:");
int count = 1;
int a = 1;
while (a < 4) { // 只有三次輸入用戶名的機會
int i;
for (i = 0; i < 3; i++) {
if (users.equals(user[i][0])) { //判斷輸入的用戶明是否存在
String password = JOptionPane.showInputDialog("請輸入密碼:");
while (count < 4) { //利用while循環控制輸入次數
if (password.equals(user[i][1])) { //判斷用戶輸入的密碼是否正確
JOptionPane.showMessageDialog(null, users
+ ", welcome!"); //正確輸出該用戶明 以及welcome!
System.exit(0);
} else {
password = JOptionPane
.showInputDialog("密碼有誤,請重新輸入密碼:");
count++;
}
if (!password.equals(user[i][1]) && count == 3) {//當用戶輸入存在的用戶明和錯誤的密碼
JOptionPane.showMessageDialog(null, "三次密碼有誤,退出!");
System.exit(0);
}
}
}
}
if (i == 3) {
JOptionPane.showMessageDialog(null, "用戶名無效,請重新輸入!");
users = JOptionPane.showInputDialog("請輸入用戶名:");
}
a++;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -