Java实现简单登陆,注册,退出
程序员文章站
2022-03-30 13:06:31
...
public static void login(int[] message){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入账号:");
int id = scanner.nextInt();
int i = 0;
for(;i<message.length;i++){
if(message[i] == id){
System.out.println("登陆成功");
break;
}
}
if(i == message.length) {
System.out.println("登陆失败");
}
}
public static void register(int[] message){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入账号:");
int id = scanner.nextInt();
//是否之前存在id,存在,注册失败
for(int i=0;i<message.length;i++){
if(message[i] == id){
System.out.println("注册失败");
return;
}
}
for(int i=0;i<message.length;i++){
if(message[i] == 0){
message[i] = id;//找到合适位置放id
System.out.println("注册成功");
break;
}
}
}
public static void main(String[] args) {
int[] message = new int[10];
while (true) {
System.out.println("1.登陆 2注册 3退出");
Scanner scanner = new Scanner(System.in);
int choice = scanner.nextInt();
if (choice == 3) {
return;
}
switch (choice) {
case 1:
login(message);
break;
case 2:
register(message);
break;
default:
System.out.println("输入错误");
}
}
}
上一篇: vue 筛选对接扣
下一篇: django登陆注册实现