首页 > 编程语言 > 详细

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

时间:2019-09-24 15:16:11      阅读:91      评论:0      收藏:0      [点我收藏+]
 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 }

 

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

原文:https://www.cnblogs.com/2940500426yingxin/p/11577854.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!