公共类回文{
public static void main(String[] args) {
String name = "aba";
StringBuilder sb = new StringBuilder();
sb.append(name);
sb = sb.reverse();
System.out.println(sb);
System.out.println(name);
if (sb.equals(name)) {
System.out.println(name + " is palindrome");
} else System.out.println(name + " isn't palindrome");
}
}else条件仅执行。
您需要使用sb.toString()
if(sb.toString().equals(name)) ...