class DengL {
public static void main(String[] args) {
User u=new User();
u.setUserName("Wan123");
u.setPassWord("12345");
for (int i = 0; i < 3; i++) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入用户名");
String name = sc.nextLine();
System.out.println("请输入密码");
String mm = sc.nextLine();
if (u.panDuan(name, mm)) {
System.out.println("登陆成功");
break;
} else {
if ((2 - i) == 0) {
System.out.println("请等2个小时后,再次登陆!");
} else
{
System.out.println("用户名密码错误,还有" + (2 - i) + "次机会");
}
}
}
// System.out.println("请等2个小时后,再次登陆!");
}
}
public class User {
private String userName;
private String passWord;
public User() {
super();
// TODO Auto-generated constructor stub
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
/**
* 这是一个判断登陆是否成功的方法。
*
*/
public boolean panDuan(String userName,String passWord){
return this.userName==userName&&this.passWord==passWord;
}
} |