所以我試圖讓用戶輸入一個字符串,向後打印,然後比較新的字符串,看看它是否是迴文或不...似乎沒有工作,我不知道爲什麼...字符串比較無法正常工作?
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.print("Enter a word: ");
String word = input.next();
StringBuilder drow = new StringBuilder(word);
drow.reverse();
System.out.println(drow);
System.out.print(" ");
String X = drow.toString();
if (word == X) {
System.out.println("That word is a palindrome");
} else {
System.out.println("That word is not a palindrome");
}
感謝爲什麼這是行不通的任何幫助......
非常感謝! – user2849489