AJPFX实列判断一个字符串是不是对称字符串
2024-10-19 16:38:10
- import java.util.Scanner;
- /**
- * 判断一个字符串是否是对称字符串
- */
- public class StringDemo {
- public static void main(String[] args) {
- // 使用键盘录入获取字符串
- Scanner sc = new Scanner(System.in);
- // 友情提示
- System.out.println("请输入一个字符串");
- // 接收录入的字符串
- String str = sc.nextLine();
- // 调用判断方法
- duiChen(str);
- }
- // 判断是不是对称字符串方法
- public static void duiChen(String str){
- boolean flag = true;
- for(int i = 0, j = str.length()-1; i <= j; i++, j--){
- // 如果第一个角标值和最后一个角标值不一样,就跳出循环
- if(str.charAt(i) != str.charAt(j)){
- flag = false;
- // 跳出循环
- break;
- }
- }
- System.out.println(str + (flag ? "是对称字符串" : "不是对称字符串"));
- }
- }
最新文章
- Lind.DDD.Domain.ISortBehavor~上移与下移
- BurpSuite使用设置
- 调用CXF工具 生成 WSDL【转】
- Spring MVC的工作流程
- CF 461B Appleman and Tree 树形DP
- Careercup - Google面试题 - 5661939564806144
- MacOS显示和不显示隐藏文件
- iframe整理学习笔记
- 实现一个基于FTP协议的程序——文件上传下载器(十三)
- 最短路 dijkstra and floyd
- Css3图片圆角,兼容所有浏览器
- Picasso – Android系统的图片下载和缓存类库
- vc 制作图片资源dll
- C#-循环滚动字幕,timer,从左至右,从右至左,暂停---ShinePans
- Failed to load the JNI shared library ";XXXXXXX";
- [Swift]LeetCode464. 我能赢吗 | Can I Win
- WebApi 增加身份验证 (OAuth 2.0方式)
- Nodejs 使用Protobuf
- LeetCode--No.004 Median of Two Sorted Arrays
- git-stash用法小结