我正在尝试比较这两个字符串以检查扫描仪输入的值是否相同。问题是在输入两个值之后,输出是说两个字符串不相同。
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
String testOne = "";
String testTwo = "";
Scanner input = new Scanner(System.in);
testOne = input.next();
Scanner inputOne = new Scanner(System.in);
testTwo = inputOne.next();
System.out.println("Before comapring: testOne = " + testOne + "\t testTwo = " + testTwo +"\n");
if(testOne == testTwo){
System.out.println("The same");
System.out.println("After comparing: TestOne = " + testOne + "\t testTwo = " + testTwo);
}
else{
System.out.println("Not The same");
System.out.println("After comparing: testOne = " + testOne + "\t testTwo = " + testTwo);
}
}
}
我已经尝试过多次输入,结果总是它们不一样。
任何想法将不胜感激。