java中回文判断

时间:2022-05-06
本文章向大家介绍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("该字符串不是回文!");
	}
}