java中回文判断

public class HuiWen {
	public static void main(String[] args) {
		String s = "abcba";
		char[] c = s.toCharArray();
		boolean b = true;
		for (int i = 0; i < c.length; i++) {
			if (c[i] != c[c.length - i - 1])
				b = false;
		}
		if (b)
			System.out.println("该字符串是回文!");
		else
			System.out.println("该字符串不是回文!");
	}
}

你可能感兴趣的:(java中回文判断)