String[] s = {"aba","3223","abccba","7890987","123123"};
String s1 = "";
for(int i=0;i<5;i++) { //第一层for循环把字符串数组转换成字符串
s1 = s;
char[] c2 =new char[s1.length()];
//System.out.println(s1);
for(int j=0;j<s1.length();j++) { // 这层for循环把字符串转换成字符数组
char c = s1.charAt(j);
c2[j] = c;
//System.out.print(c + " ");
}
for(int k=0;k<c2.length/2;k++) { // c2.length/2是判断的次数,
if(c2[k] == c2[c2.length-1-k]) {
if(k==c2.length/2-1) {
print(c2);
System.out.println("是对称的");
}
}else {
print(c2);
System.out.println("不是对称的");
break;
}
}
}
}
public static void print(char[] arr) { //遍历字符数组
for(int i=0;i<arr.length;i++) {
System.out.print(arr);
}
}
|