用递归算法判断你是否为回文

…衆ロ難τιáo~ 提交于 2019-11-30 10:05:36
 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 }

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!