package com.String;
//判断字符串是不是对称的
public class TestString01 {
public static void main(String args[]) {
String str1 = "asdfgugfdsa";
String str2 = "asdfkkgksa";
TestString01 test = new TestString01();
test.isD(str1);
test.isD(str2);
}
public void isD(String str) {
char[] c1 = str.toCharArray();
int j = c1.length - 1;
int i;
for ( i = 0; i < c1.length-1; i++) {
if (c1[i] == c1[j]) {
j--;
} else {
System.out.println(str + "不是对称的字符串");
break;
}
}
if(c1[i]==c1[j]){
System.out.println(str+"是对称字符串");
}
}
}
判断字符串是不是对称字符串
最新推荐文章于 2023-03-16 12:13:07 发布