20190925Java课堂记录(一)
2024-09-06 14:22:59
判断字符串是否回文
设计思想
利用递归,每次返回长度减二的字符串,最终返回结果
源程序代码
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!");
} }
运行结果截图
编程总结分析
利用递归可以简化代码,且便于思考问题,但占用空间过多
最新文章
- mui项目中如何使用原生JavaScript代替jquery来操作dom 转自【B5教程网】:http://www.bcty365.com/content-146-3661-1.html
- iOS APP上架过程常见问题
- <;script type=";text/javascript"; src=";<;%=path %>;/pages/js/arsis/area.js?v=1.01";>;<;/script>; 为什么在最后加? v+1.01
- [leetcode]Maximum Product Subarray @ Python
- PHP Static Self 的区别
- jquery easyui DataGrid 动态的改变列显示的顺序
- 第二百八十一、二、三天 how can I 坚持
- MSChart实例
- Necklace of Beads
- jQuery源码的一个坑
- Linux命令 file
- 你知道Java的四种引用类型吗
- B. Views Matter
- PAT 1022 D进制的A+B
- spark 中划分stage的思路
- ios开发第三方库--cocoapods安装
- codevs 2173 忠诚
- LeetCode119.杨辉三角 II
- linux下的idea的界面问题,错位以及各种...
- 如何使用动画库animate.css
热门文章
- C# “不支持给定路径的格式”异常处理
- SpringBoot 上传文件到linux服务器 异常java.io.FileNotFoundException: /tmp/tomcat.50898……解决方案
- win10 uwp 录制任意应用屏幕
- windows添加右键菜单
- C++Review6_优先队列priority_queue
- web快速开发框架 WebBuilder 8.7发布
- 序列化表单数据$(";form";).serializeArray()
- Struts||IQ
- $bzoj2560$ 串珠子 容斥+$dp$
- JDK1.8的HashMap实现原理和源码解析