判断字符串是否回文

设计思想

利用递归,每次返回长度减二的字符串,最终返回结果

源程序代码

import java.util.Scanner;

public class palindrome {
static int palin(String s, int length) {
int zt = 0;
if (length == 1 || length == 0)
return 1;
if (s.substring(0, 1) .equals( s.substring(s.length() - 1, s.length()))){
zt = 1;
palin(s.substring(1, s.length() - 1), length-2); } else
zt = 0; return zt;
} public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
int length = s.length();
if (palin(s, length) == 1) {
System.out.println("yes!"); } else
System.out.println("no!");
} }

运行结果截图

编程总结分析

利用递归可以简化代码,且便于思考问题,但占用空间过多

最新文章

  1. mui项目中如何使用原生JavaScript代替jquery来操作dom 转自【B5教程网】:http://www.bcty365.com/content-146-3661-1.html
  2. iOS APP上架过程常见问题
  3. <script type="text/javascript" src="<%=path %>/pages/js/arsis/area.js?v=1.01"></script> 为什么在最后加? v+1.01
  4. [leetcode]Maximum Product Subarray @ Python
  5. PHP Static Self 的区别
  6. jquery easyui DataGrid 动态的改变列显示的顺序
  7. 第二百八十一、二、三天 how can I 坚持
  8. MSChart实例
  9. Necklace of Beads
  10. jQuery源码的一个坑
  11. Linux命令 file
  12. 你知道Java的四种引用类型吗
  13. B. Views Matter
  14. PAT 1022 D进制的A+B
  15. spark 中划分stage的思路
  16. ios开发第三方库--cocoapods安装
  17. codevs 2173 忠诚
  18. LeetCode119.杨辉三角 II
  19. linux下的idea的界面问题,错位以及各种...
  20. 如何使用动画库animate.css

热门文章

  1. C# “不支持给定路径的格式”异常处理
  2. SpringBoot 上传文件到linux服务器 异常java.io.FileNotFoundException: /tmp/tomcat.50898……解决方案
  3. win10 uwp 录制任意应用屏幕
  4. windows添加右键菜单
  5. C++Review6_优先队列priority_queue
  6. web快速开发框架 WebBuilder 8.7发布
  7. 序列化表单数据$("form").serializeArray()
  8. Struts||IQ
  9. $bzoj2560$ 串珠子 容斥+$dp$
  10. JDK1.8的HashMap实现原理和源码解析