使用递归方式判断某个字串是否是回文

源代码

package Test;

import java.util.*;

public class test0 {

public static boolean func(String str,int start,int size)

{

if(start>=size-1)

return true;

扫描二维码关注公众号,回复: 7357558 查看本文章

if(str.toCharArray()[start]!=str.toCharArray()[size-1])

return false;

return func(str,start+1,size-1);

}

public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String s;
System.out.println("请输入字符串 :");
s=scan.nextLine();
if(func(s,0,s.length()))
System.out.println("是回文");
else
System.out.println("不是回文");

}

}

运行截图

猜你喜欢

转载自www.cnblogs.com/shenaoyu/p/11582599.html
今日推荐