java--Demo3(注册登录)

@Test
public void test(){
String[][] users=new String[0][2];
int index=0;
int loginIndex=0;
boolean flag=true;
while(flag){
System.out.println("1=注册;2=登录;3=退出");
int x=new Scanner(System.in).nextInt();

switch (x) {
case 1:
boolean rgflag = true;
while (rgflag) {
System.out.println("注册");
System.out.println("请输入账号:");
String username = new Scanner(System.in).next();
System.out.println("请输入密码:");
String userpassword = new Scanner(System.in).next();
boolean isok = false;
for (int i = 0; i < users.length; i++) {
String[] name = users[i];
String ming = name[0];
if (ming.equals(username)) {
isok = true;


}
}
if (isok) {
System.out.println("该用户已存在,请重新注册!");
} else {
String[] yonghu = { username, userpassword };
users = Arrays.copyOf(users, users.length + 1);
users[index] = yonghu;
index++;
System.out.println("注册成功,是否继续注册?y/n");
String input = new Scanner(System.in).next();
if (input.equals("n")) {
rgflag = false;
}
}
}
break;


case 2:
System.out.println("登录");
boolean loginTotleflag=true;
while(loginTotleflag){
System.out.println("请输入账号:");
String username=new Scanner(System.in).next();
boolean isok=false;
for(int i=0;i String[] name=users[i];
String ming=name[0];
if(ming.equals(username)){
isok=true;
loginIndex=i;
}
}
if(isok){
boolean loginflag=true;
while(loginflag){
System.out.println("请输入密码:");
String userpassword=new Scanner(System.in).next();
//for(int i=0;i String pwd=users[loginIndex][1];
if(pwd.equals(userpassword)){
System.out.println("登录成功suceess!!!!!!");
loginflag=false;
loginTotleflag=false;

}else{
System.out.println("密码不正确!!!");
}
//}
}

}else{
System.out.println("没有此用户,请重新输入");
}
}



break;
case 3:
System.out.println("谢谢使用!");
flag=false;
break;

default:
System.out.println("输入有误!");
break;
}
}
}

你可能感兴趣的:(java--Demo3(注册登录))