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时执行
能成功判断
这个应该没有问题吧。
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");
}
没看懂你的意思。。
package Account_system;
import java.io.IOException;
import java.util.Scanner;
class Account{
private String account="66";
private String code="sada";
protected Account() {
}
public int system(String account, String code) {
return(account.equals(this.account)&&account.equals(this.account))?1:0;
}
}
//以下是测试类
public class TestAccount_System {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner sc = new Scanner(System.in);
System.out.println("账号:");
String account = sc.next();
System.out.println("密码:");
String code = sc.next();
Account team = new Account();
int s = team.system(account,code);
switch (s) {
case 1 -> {
System.out.println("超级管理员账号登录成功");
// 调用命令行解释器cmd 传参 一个允许调用内置命令的命令的参数/c 调用内置命令cls
//new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
}
}
}
没看懂你这个代码是干吗的
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];
似乎你的SuperAccount_set 没有赋值,
SuperAccount_set[i]都是null,
account.equals(SuperAccount_set[i])能判断通过才怪呢。
还有你上面的String[] SuperAccount_set = {"1481524103" }; 赋值也不对啊,这样set只有一个元素。
这个地方换成string比较好。