package jiegouSuanfa;
import java.util.Scanner;
/**
* 判断一个字串是否是回文
* @author 97699
*
*/
public class PalindromeTest {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.next();
char[] ca=str.toCharArray();
System.out.println("从两边向中间判断:"+HT(ca));
System.out.println("从中间向两边判断:"+LR(ca));
}
/**
* 从中间向两边判断
* @param ca
* @return
*/
private static boolean LR(char[] ca) {
// TODO Auto-generated method stub
int length=ca.length-1;
int left=length%2==0?length/2-1:length/2;
int right=length/2+1;
while(left>=0) {
if(ca[left]!=ca[right]) {
return false;
}
left--;
right++;
}
return true;
}
/**
* 从两边开始判断
* @param ca
* @return
*/
private static boolean HT(char[] ca) {
// TODO Auto-generated method stub
int head=0;
int tail=ca.length-1;
while(head<tail) {
if(ca[head]!=ca[tail]) {
return false;
}else {
head++;
tail--;
}
}
return true;
}
}