-----------------------用户登陆原----------------------------
public class Check {
public static void main(String[] args) {
//创建一个adm数组
Admin[] adm = new Admin[3];
//三个账号
adm[0] = new Admin("admin", "pastNumber");
adm[1] = new Admin("admin1", "pastNumber");
adm[2] = new Admin("admin2", "pastNumber");
//使用标准输入流函数,从键盘输入一些信息
Scanner scan = new Scanner(System.in);
System.out.println("请输入你的账号:");
//将输入的账号放入putName
String putName = scan.next();
System.out.println("请输入你的账号密码:");
//将输入的密码放入普通putPassNumber中
String putPassNumber = scan.next();
//新建一个布尔型和整型数据,布尔值 用于判断,整型判断是那个账号登陆
boolean past = false;
int pastN = 0;
//判断账号密码是否正确
for(int i=0;i<adm.length;i++){
if(adm[i].getName().equals(putName)&&adm[i].getPastNumber().equals(putPassNumber)){
past = true;
pastN = i;
break;
}
}
//输出账号密码是否正确
if(past){
System.out.println("欢迎" + adm[pastN].getName() + "登陆");
}
else{
System.out.println("输入有误,请正确输入你的账号和密码!");
}
}
}
class Admin{
private String name;
private String pastNumber;
Admin(String name, String pastNumber){
this.name = name;
this.pastNumber = pastNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPastNumber() {
return pastNumber;
}
public void setPastNumber(String pastNumber) {
this.pastNumber = pastNumber;
}
}
运行结果为:
当密码或者账号不正确的时候输出结果是:
posted on 2010-10-18 01:32
tovep 阅读(160)
评论(0) 编辑 收藏