问题遇到的现象和发生背景
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时执行
我想要达到的结果
能成功判断