回文字符串

Posted 终会飞翔

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了回文字符串相关的知识,希望对你有一定的参考价值。

import java.util.Scanner;

/**
 * 给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的
 * @author kif
 *
 */
public class Palindrome {
	
	public static void judge(String str){
		String sOne = str.substring(0, str.length()/2);
		System.out.println(sOne.startsWith(new StringBuffer(str).reverse().substring(0, str.length()/2)));
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		String str = input.nextLine();
		Palindrome.judge(str);
		input.close();
	}

}

 

以上是关于回文字符串的主要内容,如果未能解决你的问题,请参考以下文章