importjava.util.*;publicclassassignment{publicstaticvoidmain(String[]args){Stringiscontinue;//是否继续标识符do{//系统主菜单System.out.println("*****欢迎进入系统*****");Sy...
import java.util.*;
public class assignment {
public static void main(String[] args) {
String iscontinue; //是否继续标识符
do{
//系统主菜单
System.out.println("*****欢迎进入系统*****");
System.out.println("\t\t1.注册");
System.out.println("\t\t2.登录");
System.out.println("*******************************");
Scanner input = new Scanner(System.in);
System.out.print("请选择菜单:");
int num = input.nextInt();
switch(num){
case 1:
//用户注册系统
String username = "",password = "",passwordagain = ""; //定义用户名和密码
boolean rename=true; //重名标识符
String userinfo[] = new String[1000]; //存放用户注册信息
System.out.println("[奖客富翁系统>注册]"); //注册会员信息
System.out.println("请填写个人注册信息:");
while(true){
rename = false; //重名恢复默认值
System.out.print("用户名:");
username = input.next();
int j = 0;
for(int i = 0;i
if(username.equals(userinfo[j])){
rename = true;
break;
}
j++;
}
if(rename){
System.out.print("您输入的用户名被注册,请选择其他用户名!");
continue;
}
System.out.print("密码:");
password = input.next();
System.out.print("再次输入密码:");
passwordagain = input.next();
if(!passwordagain.equals(password)){ //验证两次输入密码是否一致
System.out.println("两次密码输入不一致,请重新输入!");
continue;
}
System.out.println("[注册成功,请记好您的用户名和密码"); //注册成功
System.out.println("用户名\t密码");
System.out.println(username+"\t\t"+password);
break;
}
case 2:
//用户登录系统
System.out.println("[奖客富翁系统>登录]"); for(int i = 2;i>=0;i--){
System.out.print("请输入用户名:");
String username1 = input.next();
System.out.print("请输入密码:");
String password1 = input.next();
if((username.equals(username1))&&(password.equals(password1))){ //验证输入用户名和密码是否正确
System.out.print("欢迎进入!");
break;
}else{
System.out.print("输入错误,您还有"+i+"次机会!");
if(i == 0){
System.out.println("\n对不起,您3次均输入错误!");
break;
}
}
}
break;
default:
System.out.println("您的输入有误,请重新输入!");
break;
}
System.out.print("继续吗?(y/n):");
iscontinue = input.next();
}while("y".equals(iscontinue));
System.out.println("系统退出,谢谢使用!");
}
}
展开