Recursive algorithm to determine whether you palindrome

 1 package firs;
 2 
 3 import java.util.Scanner;
 4 
 5 public class Digui {
 6 private  static int a;
 7 private static int b=0;
 8 public static void ok(String str,int i)
 9 {
10     if(i==a/2||i==a/2+1)
11     {
12         System.out.println("yes");
13     }
14     else 
15     {
16         if(str.charAt(i-1)==str.charAt(b))
17         {
18             i--;
19             b++;
20             ok(str,i);
21         }
22         else 
23         {
24             System.out.println("no");
25         }
26     }
27 }
28 public static void main(String[] args) {
29     Scanner input=new Scanner(System.in);
30     String str;
31     str=input.next();
32     a=str.length();
33     ok(str,a);
34 }
35 }

 

Guess you like

Origin www.cnblogs.com/2940500426yingxin/p/11577854.html