1987891这个就是回文,判断“1987891”是不是回文?
1
public static boolean isPalindrome(String str) { return str.equals( new StringBuilder(str) .reverse() .toString() ); }
2
public static boolean isPalindrome(String str) { int n = str.length(); for (int i = 0; i < n; ++i) { if (str.charAt(i) != str.charAt(n-i-1)) return false; } return true; }