public class Test {
public static void main(String[] args) {
// 定义一个源字符串
String sourceStr = "abba";
// 将源字符串转换成StringBuilder
StringBuilder stringBuilder = new StringBuilder(sourceStr);
// 将stringBuilder转换成字符串
String destStr = stringBuilder.reverse().toString();
// 判断源字符串是否相等,如果相等,那么源字符串对称,否则,不对称
if(destStr.equals(sourceStr)){
System.out.println(sourceStr+" 为对称字符串");
}else{
System.out.println(sourceStr+" 为不对称字符串");
}
}
}
|
|