public class CC {
//该方法判断是不是回问串
public boolean palindromeString(String word) {
boolean ifPalindromeString = true;
for (int i = 0; i < word.length() / 2; i++) {
if (!(word.substring(i, i + 1).equals(word.substring(word.length()
- i - 1, word.length() - i)))) {
ifPalindromeString = false;
}
}
return ifPalindromeString;
}
//调用测试
public static void main(String[] args) {
CC c = new CC();
boolean ifPalindromeString = c.palindromeString("Q1QQQ"); //你在这里加字符串测试。
if (ifPalindromeString) {
System.out.println("是回文串");
} else {
System.out.println("不是回文串");
}
}
}