Can determine whether the palindrome

        A write function, the use of a recursive function in the recursion stops when the condition that the input string with charArt () function to read the first character pour stop recursive, recursive action is more positive and reverse sequence of characters corresponding to the ,

Finally, if the same reverse regular palindrome, the palindrome is not different.

package pp;

import java.util.Scanner;

public class wd{
public static Scanner scan = new Scanner(System.in);
public static int digui(String a, int b)
{ int m=1;
if(b==0)
{return m;}
char x=a.charAt(b-1);
char y=a.charAt(a.length()-b);
if(x==y)
{
digui(a,b-1);
}
else
{m=2;}
return m;
}

public static void main(String args[]){
int m;
String a;
int b;
a=scan.next();
b=a.length();
m=digui(a,b);
if(m==1){
System.out.println("可以回文");
}
if(m==2){
System.out.println("不可以回文");
}
}}

 

 

Guess you like

Origin www.cnblogs.com/yyl141/p/11586722.html