java算法回文体的判断
import java.util.*;
import java.math.BigInteger;
import java.util.Scanner;
public class Test{
static Scanner a=new Scanner(System.in);
static char str[] = new char[99];
static int l=0;
public static void main(String[] args) {
System.out.println("请输入字符串:");
String b = a.next();
for(int i=0;i<b.length();i++) {//字符数组
str[l] = b.charAt(i);
l++;
}
boolean hw = Huiwen(str, 0, l-1,l);
if(hw) {
System.out.println("是回文");
}
else
{
System.out.println("不是是回文");
}
}
public static boolean Huiwen(char a[],int first,int end,int length){
if(length == 1 || length == 0)
return true;
if (a[first] != a[end] || first >= end) {//第一个字符与最后一个字符比较
return false;
}
return Huiwen(a, first + 1, end -1,length -2);//两边靠拢
}
}