java判断字符串是否回文

java判断字符串是否回文

 

/**
 * java判断字符串是否回文<br><br>
 * 基本思想是利用字符串首尾对应位置相比较
 * 
 * @author InJavaWeTrust
 *
 */
public class Palindrome {

	public static boolean isPalindrome(String str) {
		boolean bool = true;
		for (int i = 0; i <= str.length() / 2; i++) {
			if (str.charAt(i) != str.charAt(str.length() - i - 1)) {
				bool = false;
				break;
			}
		}
		return bool;
	}

	public static void main(String[] args) {
		String str = "123er321";
		System.out.println(isPalindrome(str));
	}

}

 

猜你喜欢

转载自injavawetrust.iteye.com/blog/2295155