开发者社区> 问答> 正文

部分代码第二次不起作用,idk为什么[关闭]

我的部分代码有问题,它不起作用,我不知道为什么

第一次,当我调用此“问题”方法时,一切都很好,但是第二次,它仅执行部分代码。我认为这是switch语句的问题,所以我用if更改了它,但没有帮助

下面是控制台输出的问题,并链接到代码

抱歉,我是新来的,我找不到如何在此处发布所有代码,网站显示了一些奇怪的红色错误消息,所以我通过docs将其发布在这里,我希望它可以:)

问题是添加/删除图书馆员或注销选项

https://docs.google.com/document/d/1FrvjUnPgQR6iRtqqHT4dWwIG8VaGmEJIBvs1nctCHmM/edit

[控制台输出1

编辑:这是您可以在控制台输出中看到的此方法和问题

public static void adminAccess() {
    adminAccess = true;
    System.out.println("test, admin access = " +adminAccess);
    System.out.println("--logged in as admin");

    while(adminAccess) {
        System.out.println("test, code after if, inside while 1");
        System.out.print("1)add librarian \n2)delete librarian \n9)logout \n>>>"); 
        System.out.println("test, code after if, inside while 2");
        int input = scan.nextInt();

        System.out.println("test, code after if, inside while 3");


        if(input == 1) {
            admin.addLibrarian();
        }

        else if(input == 2) {
            admin.deleteLibrarian();
        }
        else if(input ==9) {
            adminAccess = false;
            logOut();   
        }
        System.out.println("test, code after if, inside while 4");
    }   System.out.println("test, code after while");

edit2:如果有人告诉我或指出我可以更改的内容,我将很乐意,因此代码甚至第二次显示选项:1)添加图书管理员\ n2)删除图书管理员\ n9)注销?谢谢

展开
收起
几许相思几点泪 2019-12-08 21:50:32 424 0
0 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载