我新研究的方法
- public class IsSymmetry {
- public static void main(String[] args) {
- boolean flag = isSymmetry("abba");
- if(flag)
- System.out.println("是对称的!");
- else
- System.out.println("不是对称的!");
- }
- private static boolean isSymmetry(String string) {
- if(string.length()<=1){
- return false;
- }
- boolean flag = string.length()%2==0?false:true;
- int x = string.length()/2;
- if(flag){
- return string.substring(0,x).equals(new StringBuilder(string.substring(x+1,string.length())).reverse().toString());
- }
- else{
- return string.substring(0,x).equals(new StringBuilder(string.substring(x,string.length())).reverse().toString());
- }
- }
- }
复制代码 |