1. import java.util.Scanner;
  2. /**
  3. *        判断一个字符串是否是对称字符串
  4. */
  5. public class StringDemo {
  6. public static void main(String[] args) {
  7. // 使用键盘录入获取字符串
  8. Scanner sc = new Scanner(System.in);
  9. // 友情提示
  10. System.out.println("请输入一个字符串");
  11. // 接收录入的字符串
  12. String str = sc.nextLine();
  13. // 调用判断方法
  14. duiChen(str);
  15. }
  16. // 判断是不是对称字符串方法
  17. public static void duiChen(String str){
  18. boolean flag = true;
  19. for(int i = 0, j = str.length()-1; i <= j; i++, j--){
  20. // 如果第一个角标值和最后一个角标值不一样,就跳出循环
  21. if(str.charAt(i) != str.charAt(j)){
  22. flag = false;
  23. // 跳出循环
  24. break;
  25. }
  26. }
  27. System.out.println(str + (flag ? "是对称字符串" : "不是对称字符串"));
  28. }
  29. }

最新文章

  1. Lind.DDD.Domain.ISortBehavor~上移与下移
  2. BurpSuite使用设置
  3. 调用CXF工具 生成 WSDL【转】
  4. Spring MVC的工作流程
  5. CF 461B Appleman and Tree 树形DP
  6. Careercup - Google面试题 - 5661939564806144
  7. MacOS显示和不显示隐藏文件
  8. iframe整理学习笔记
  9. 实现一个基于FTP协议的程序——文件上传下载器(十三)
  10. 最短路 dijkstra and floyd
  11. Css3图片圆角,兼容所有浏览器
  12. Picasso – Android系统的图片下载和缓存类库
  13. vc 制作图片资源dll
  14. C#-循环滚动字幕,timer,从左至右,从右至左,暂停---ShinePans
  15. Failed to load the JNI shared library &quot;XXXXXXX&quot;
  16. [Swift]LeetCode464. 我能赢吗 | Can I Win
  17. WebApi 增加身份验证 (OAuth 2.0方式)
  18. Nodejs 使用Protobuf
  19. LeetCode--No.004 Median of Two Sorted Arrays
  20. git-stash用法小结

热门文章

  1. Struts2框架起源
  2. LeetCode题解汇总
  3. web.xml中的ServletContextListener
  4. 找不到方法 Void Newtonsoft.Json.JsonConvert.set_DefaultSettings
  5. hdu2099 整除的位数(暴力)
  6. VS创建Web项目提示配置IISExpress失败
  7. UVA 437 The Tower of Babylon巴比伦塔
  8. wget和curl
  9. 浏览器同部署了https的服务器交互的过程
  10. ABAP 创建和调用WebService