SHHW 2022-05-28 18:36 采纳率: 66.7%
浏览 54
已结题

Java中if判断字符串

问题遇到的现象和发生背景

Java中if字符串判断条件不成立

问题相关代码,请勿粘贴截图
package Account_system;

public class Account {
    Account() {
        String[] SuperAccount_set = {"1481524103" };
        String[] Suprecode_set = {"asdfghjkl" };
        String[] Account_set = {"3089095811" };
        String[] code_set = {"123123" };
        System.out.println("66");
    }

    String[] SuperAccount_set = new String[10];
    String[] Suprecode_set = new String[10];
    String[] Account_set = new String[100];
    String[] code_set = new String[100];

    public int system(String account, String code) {
        int s = 0;
        while (true) {
            int i = 0;
            i++;
            if (account.equals(SuperAccount_set[i]) && code.equals(Suprecode_set[i])) {
                s = 1;
                System.out.println("esc");
            } else {
                if (account.equals(Account_set[i]) && code.equals(code_set[i])) {
                    s = 2;
                    System.out.println("ess");
                }
            }
            break;
        }
        System.out.println(s);
        return s;
    }

}


//以下是测试类
package Account_system;

import java.io.IOException;
import java.util.Scanner;

public class TestAccount_System {
    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner(System.in);
        Account team = new Account();
        System.out.println("账号:");
        String account = sc.next();
        System.out.println("密码:");
        String code = sc.next();
        int s = team.system(account,code);
        switch (s) {
            case 1 -> {
                System.out.println("超级管理员账号登录成功");
                // 调用命令行解释器cmd 传参 一个允许调用内置命令的命令的参数/c  调用内置命令cls
                //new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();

            }
        }
    }
}

运行结果及报错内容

66
账号:
liuliu
密码:
sada
0

我的解答思路和尝试过的方法

if条件更改过,但依旧不成立,条件为true时执行

我想要达到的结果

能成功判断

  • 写回答

3条回答 默认 最新

  • 兔崽子° 2022-05-28 18:57
    关注

    这个应该没有问题吧。

    Account() {
            String[] SuperAccount_set = {"1481524103" };
            String[] Suprecode_set = {"asdfghjkl" };
            String[] Account_set = {"3089095811" };
            String[] code_set = {"123123" };
            System.out.println("66");
        }
    //这是你预设的两个账号及密码,你输入的账号及密码都是和这里做判断的。根据你输入的账号liuliu及密码,当然会返回0.
    
    //如果要用你输入的账号返回成功,改下这里应该就好了
    Account() {
            String[] SuperAccount_set = {"liuliu" };//账号
            String[] Suprecode_set = {"sada" };//密码
            String[] Account_set = {"3089095811" };
            String[] code_set = {"123123" };
            System.out.println("66");
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 9月15日
  • 已采纳回答 9月7日
  • 创建了问题 5月28日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效