import java.util.Scanner;
public class lian{
public static void main(String[]args){
boolean in=true;
int count= 0;
liang xian = new liang();
while (in){
System.out.println("===登录系统===");
System.out.println("1.登录");
System.out.println("2.注册");
System.out.println("3.查看");
System.out.println("4.退出");
System.out.println("==注意== 未注册的用户请先注册");
System.out.println("请输入编号进行操作");
Scanner scanner = new Scanner(System.in);
int button = scanner.nextInt();
if(button == 1){//登录功能
xian.login(count);
}else if(button == 2){//注册功能
count++;
xian.register(count);
}else if(button == 3){//查看功能
xian.View(count);
}else if(button == 4){//退出功能
System.out.println("退出系统Y/N");
String kg = scanner.next();
if("Y".equals(kg)){
in = false;
}else{
in = true;
}
}
}
}
}
class liang{
String [] [] arr = new String[100][2];//100个用户位,每个用户有1账号和1秘密
Scanner scanner = new Scanner(System.in);
// 注册方法
public void register(int count){
System.out.print("请输入账号名:");
String zh = scanner.next();
System.out.print("请输入密码:");
String mm = scanner.next();
arr[count][0]=zh;
arr[count][1]=mm;
System.out.println("注册成功!!");
}
//登入方法
public void login(int count){
System.out.print("请输入账号:");
String zhh = scanner.next();
System.out.print("请输入密码:");
String mmm = scanner.next();
for (int i=1; i<arr.length; i++){
if(i<=count){
if(zhh.equals(arr[i][0])){
if(mmm.equals(arr[i][1])){
System.out.println("登录成功");
}else {
System.out.println("登陆失败");
}
}
}else {
break;
}
}
}
// 查看方法
public void View (int count){
for(int i = 1; i< arr.length;i++){
if (i<=count){
System.out.println("用户"+i);
System.out.println("账号:"+arr[i][0]);
System.out.println("密码:"+arr[i][1]);
}else{
break;
}
}
}
}
Java基础-登录注册-作业
最新推荐文章于 2024-04-07 01:13:31 发布