package work;
import java.util.*;
public class youxiang {
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.println("請輸入一個字符串");
String s=input.next();
StringBuffer SB=new StringBuffer(s);
System.out.println(SB.reverse());
String str=SB.toString(SB.reverse());
if(s==str){
System.out.println("該字符串是回文");
}
}
}
根據你的代碼推斷你的意圖和需求應該這樣寫
package work;
import java.util.*;
public class youxiang {
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.println("請輸入一個字符串");
String s=input.next();
StringBuffer SB=new StringBuffer(s);
System.out.println(SB.reverse());
String str=SB.toString(SB.reverse());
if(s.equals(str)){
System.out.println("該字符串是回文");
}
}
}