MC豹哥2005 2020-10-06 20:11 采纳率: 50%
浏览 71
已采纳

在执行循环嵌套时,出现重复现象

源代码:
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList array = new ArrayList();
Teacher teacher=new Teacher();
ArrayListarr=new ArrayList() ;
Student student = new Student();//实例化对象
boolean a=true,a1=true;

    System.out.println("=============欢迎使用疫情的打卡后台管理系统=============");
    while (true) {

        System.out.println("请选择:1.老师打卡管理 2.学生打卡管理 0.退出系统");
       // String temp=sc.nextLine();
       // boolean flag=temp.matches("[0-9]+");
        int line=sc.nextInt();
        if (line==0||line==1||line==2){

         //   int line=Integer.parseInt(temp);
            switch (line) {

                case 1:
                    while (a1) {
                        System.out.println("请选择:1.录入打卡信息 2.删除打卡信息 3.查询打卡信息 4.返回上级菜单");
                        int jieshou = sc.nextInt();
                        switch (jieshou) {
                            case 1:
                                teacher.addTeacher(arr);
                                break;
                            case 2:
                                teacher.deleteTeacher(arr);
                                break;
                            case 3:
                                teacher.updateTeacher(arr);
                                break;
                            case 4:
                                a1=false;
                                break;
                        }
                    }continue;

                case 2:

                    while (a) {
                        System.out.println("请选择:1.录入打卡信息 2.删除打卡信息 3.查询打卡信息 4.返回上级菜单");
                        int jieshou1 = sc.nextInt();
                        switch (jieshou1) {
                            case 1:
                                student.addStudent(array);
                                break;
                            case 2:
                                student.deleteStudent(array);
                                break;
                            case 3:
                                student.updateStudent(array);
                                break;
                            case 4:
                                a=false;
                                break;
                        }
                    }continue;

                case 0:
                    System.out.println("您已退出疫情打卡管理系统,欢迎再次使用!");
                    System.exit(0);//JVM退出
            }
        }else {
            System.out.println("您的输入有误,请重新输入!");
        }
        }

    }
}
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-10-06 23:31
    关注

    boolean a=true,a1=true;
    这两个要写在外侧while的里面,否则一旦退出菜单就进不去了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan