标签:system 循环 builder test 反转 print string end star
@Test
public void b() {
int[] arr = new int[]{1, 2, 3, 4, 5, 4, 3, 2, 1};
int start = 0;
int end = arr.length - 1;
while (start <= end) {
if (arr[start] != arr[end]) {
System.out.println("此数组不对称");
System.exit(0);
} else {
start++;
end--;
}
}
System.out.println("此数组是对称的!!");
}
判断字符串元素是否对称
@Test
public void a() {
//将字符串反转,反转之后的字符串和原本的比较
String str = "ABCCBA";
StringBuilder strRev = new StringBuilder(str).reverse();
if (str.contentEquals(strRev)) {
System.out.println("该字符串是对称的!");
} else {
System.out.println("该字符串不是对称的!");
}
}
标签:system 循环 builder test 反转 print string end star
原文地址:https://www.cnblogs.com/liqiliang1437/p/13887279.html