欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

java 确定 String 字符串是否为回文字符串的几种常用解决方案--方法二:

最编程 2024-06-08 08:03:52
...
/*
	 * 
	 * 用StringBuilder反转
	 */
	public static void method2(){
		String s="12321";
		StringBuilder sb=new StringBuilder(s);
		String b=sb.reverse().toString();//反转后转成字符串输出
		if(s.equals(b)){
			System.out.println(s+"是回文");
		}else{
			System.out.println(s+"不是回文");
		}
	}

推荐阅读