对称的

/**
* 分析以下需求,
* 定义数字字符串数组{"010","3223","666","7890987","123123"}
* 判断该数字字符串数组中的数字字符串是否是对称
* (第一个数字和最后一个数字相等,第二个数字和倒数第二个数字是相等的,依次类推)
* (3)如:010 是对称的,3223 是对称的,123123 不是对称的
*
*/
public class Test07 {
public static void main(String[] args) {
String arr[] = {"010","3223","666","7890987","123123"};
for (int i = 0; i < arr.length; i++) {
String s = arr[i];
StringBuilder sb = new StringBuilder(s);
StringBuilder reverse = sb.reverse();
String s1 = reverse.toString();
if(s1.equals(s)){
System.out.println(s+"是对称的");
}else {
System.out.println(s+"不是对称的");
}
}
}
}

猜你喜欢

转载自www.cnblogs.com/YRSWBY2016/p/12017118.html
今日推荐