javakamo 2021-10-14 14:20 采纳率: 100%
浏览 73
已结题

if句输出结果有问题,求修改下

case2的if句我不管输入什么这里输出都是all is true, you can log in和error,没有进行判断。主要出现在第二次logon,然后再login就无法判断了。

img

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2021-10-14 14:21
    关注
    import java.util.Scanner;
    public class Test {
        public static void main(String[] args){
            String[]usersname=new String[50];
            String[]passwords=new String[50];
            String[]phonenumber=new String[50];
            Scanner input =new Scanner(System.in);
            for1:for(int n=0;n<50;n++){
                System.out.println("enter a number: ");
                System.out.println("1.logon");
                System.out.println("2.login");
                System.out.println("3.forget");
                System.out.println("4.exit");
                int situation=input.nextInt();
                switch (situation) {
                    case 1:
                        System.out.println("input your name:");
                        String name=input.next();
                        System.out.println("input your passwords:");
                        String words=input.next();
                        System.out.println("input your phone numbers:");
                        String numbers=input.next();
                        usersname[n]=name;
                        passwords[n]=words;
                        phonenumber[0]=numbers;
                        continue for1;
                    case 2:
                        System.out.println("input your name:");
                        String name1=input.next();
                        System.out.println("input your passwords:");
                        String words1=input.next();
                        boolean flag=false;
                        for(int i=0;i<50;i++){
                            if(usersname[i].equals(name1) && passwords[i].equals(words1)){
                                flag=true;
                                break;
                            }
                        if (flag){
                            System.out.println("all is true, you can log in.");
                        }else{
                            System.out.println("error");
                        }
                        }
                        continue for1;
                    case 3:
                    case 4:
                        break for1;
                    default:
                        System.out.println("error");
                }
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月14日
  • 已采纳回答 10月14日
  • 修改了问题 10月14日
  • 创建了问题 10月14日

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记