package chapter34;
import java.util.Scanner;
public class index {
//存储用户名和密码
public static String arr1[]=new String[3];//这一句是什么意思啊?new String[3]是什么意思?
public static String arr2[]=new String[3];
static int index=0;
public static void main(String[] args) {
//设置登录的默认账号和密码
arr1[0] = "heima";
arr2[0] = "123456";
//循环选择功能
while (true) {
print();
Scanner scanner = new Scanner(System.in);
System.out.println("请选择功能:");
String str = scanner.next();
if (str.equals("1")) {
login();
} else if (str.equals("2")) {
register();
} else if (str.equals("3")) {
show();
} else if (str.equals("0")) {
System.exit(0);//强制退出
} else {
System.out.println("请正确选择功能");
}
}
}
public static void print(){
System.out.println("-----------黑马管理系统--------------");
System.out.println("1.登录功能(login)");
System.out.println("2.注册功能(register)");
System.out.println("3.查看(show)");
System.out.println("0.退出(exit)");
System.out.println("-----------黑马管理系统--------------");
}
//这里选择了功能1之后,就跳转到这里
public static void login(){
//这里进行循环干嘛?
for (int i=0;i<3;i++){
Scanner scanner=new Scanner(System.in);
System.out.println("请输入用户名:");
String str1=scanner.next();
System.out.println("请输入密码:");
String str2=scanner.next();
//这里的循环是什么?
for(int i1=0;i1<arr2.length;i1++){
if (str1.equals(arr1[i1]) && str2.equals(arr2[i1])){
System.out.println("登录成功");
return;
}
}
System.out.println("登录失败,请重新登录!");
}
}
public static void register(){
Scanner scanner=new Scanner(System.in);
System.out.println("请输入用户名:");
String str1=scanner.next();
Scanner scanner1=new Scanner(System.in);
System.out.println("请输入密码:");
String str2=scanner1.next();
boolean flag=true;
for(int i=0;i<arr1.length;i++){
if(str1.equals(arr1[i])){
System.out.println("用户名已存在");
flag=false;
}
}
if (flag=true){
for(int i=0;i<arr1.length;i++){
if (str1.equals(arr1[i])){
System.out.println("用户名已存在");
flag=false;
}
}
if (flag==true){
index++;
if(index<arr1.length){
arr1[index]=str1;
arr2[index]=str2;
System.out.println("注册成功");
}else {
add();
arr1[index]=str1;
arr2[index]=str2;
System.out.println("注册成功");
}
}
}
}
public static void add(){
String newarry1[]=new String[arr1.length+3];
String newarry2[]=new String[arr1.length+3];
System.arraycopy(arr1,0,newarry1,0,arr1.length);
System.arraycopy(arr2,0,newarry2,0,arr1.length);
arr1=newarry1;
arr2=newarry2;
show();
}
public static void show(){
for(int i=0;i<arr1.length;i++){
if(arr1[i]!=null){
System.out.println("用户名:"+arr1[i]+","+"密码:"+arr2[i]+"\n");
}
}
}
}
求解注释里面的问题,详解必采纳