/*
判断一个字符串是否是对称字符串
例如"abc"不是对称字符串,"aba"、"abba"、"aaa"、"mnanm"是对称字符串
*/
class Text3
{
public static void main(String[] args)
{
String str = "abcdefgfedcba";
cmp();
}
public static void cmp()
{
boolean result = true;
int count =(str.length()-1)/2;
for (int x=0;x<count ;x++ )
{
if(str.charAt(x)!=str.charAt(str.length()-1-x))
result = false;
}
if(result)
System.out.println("该字符串是不对称的");
else
System.out.println("该字符串是对称的");
}
}
|