我在测试以下代码时出现了问题:
import java.util.Scanner;
import java.io.*;
public class pass {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
final String ago = "Bandysol";
final String bgo = "YUANMOPRE01";
System.out.println("原魔");
System.out.println("Versios 1.0.0 PRE1");
System.out.println("登录");
System.out.print("账号:");
String a = scan.next();
System.out.print("密码:");
String b = scan.next();
if (a == ago) {
if (b == bgo) {
System.out.println("登录成功!");
System.out.println("正在进入游戏");
System.out.println("欢迎!");
System.out.println("选择国家");
System.out.println("‘m’为蒙德。‘l’为璃月。‘d’为稻妻。");
System.out.print("请选择:");
String c = scan.next();
if (c == "m") {
System.out.println("正在制作中!");
}
if (c == "l") {
System.out.println("正在制作中!");
}
if (c == "d") {
System.out.println("正在制作中!");
} else {
System.out.print("错误!");
}
}
}
if (a != "Bandysol") {
if (b != "YUANMOPRE01") {
System.out.println("输入的账号或密码不正确!");
}
}
}
}
测试时即使输入的“账号”和“密码”准确无误,系统也会提示“输入的账号或密码不正确!”。
在后面让他比较我的输入和ago、bgo,它输出了一个false。
但是让他输出我的输入和ago、bgo,是个人都能看出来他们一模一样。
调试模式代码:
import java.util.Scanner;
import java.io.*;
public class passpre {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
final String ago = "Bandysol";
final String bgo = "YUANMOPRE01";
System.out.println("原魔");
System.out.println("Versios 1.0.0 PRE1");
System.out.println("登录");
System.out.print("账号:");
String a = scan.next();
System.out.print("密码:");
String b = scan.next();
if (a == ago) {
if (b == bgo) {
System.out.println("登录成功!");
System.out.println("正在进入游戏");
System.out.println("欢迎!");
System.out.println("选择国家");
System.out.println("‘m’为蒙德。‘l’为璃月。‘d’为稻妻。");
System.out.print("请选择:");
String c = scan.next();
if (c == "m") {
System.out.println("正在制作中!");
}
if (c == "l") {
System.out.println("正在制作中!");
}
if (c == "d") {
System.out.println("正在制作中!");
} else {
System.out.print("错误!");
}
}
}
if (a != "Bandysol") {
if (b != "YUANMOPRE01") {
System.out.println("输入的账号或密码不正确!");
}
}
System.out.println(a);
System.out.println(ago);
System.out.println(b);
System.out.println(bgo);
boolean d = a == ago;
boolean e = b == bgo;
System.out.println(d);
System.out.println(e);
}
}
JDK版本:18.0.1.1
有没有人告诉我怎么解决啊!