判断是否为回文字符
来源:互联网 发布:windows平板镜像下载 编辑:程序博客网 时间:2024/05/16 14:09
要求:用户输入一串字符,程序判断这个字符串是否为回文,并输出判断结果。
java实现:
package test1;import java.util.Scanner;public class IsPalindrome {public static void main(String[] args) {boolean indicator = true;//设置一个标志System.out.println("Please input a string:");//提示用户输入字符串Scanner input = new Scanner(System.in);String inStr = input.nextLine().trim();//取出输入的字符串,并且去掉最后的回车//首尾比较判断是否为回文for (int i = 0, j = inStr.length() - 1; i <= j; i++, j--){if (!(inStr.substring(i, i + 1).equals(inStr.substring(j, j + 1))))//注意不是用==判断{indicator = false;break;//不相等时设置标志,然后直接退出循环}}if (indicator){System.out.println("Is palindrome.");}else{System.out.println("Not palindrome.");}}}
阅读全文
1 0
- 判断是否为回文字符
- 判断字符序列是否为回文
- 判断是否为回文数或回文字符
- 判断字符是否回文
- 判断是否为回文
- 判断是否为回文
- 判断是否为回文
- 判断是否为回文
- 判断是否为回文
- 判断是否为回文
- 判断字符串是否为回文
- 判断是否为回文数
- 判断是否为回文数
- 判断字符串是否为回文
- 判断是否为回文数
- 判断是否为回文数
- 判断是否为回文数
- 判断是否为回文数
- ES7 decorator 从入门到放弃
- Codeforces Round #431 (Div. 2)
- win7 安装goahead服务器
- 关于操作数据库的一些笔记
- [leetcode] 53. Maximum Subarray
- 判断是否为回文字符
- python numpy模块/库
- linux权限-bash: ./startup.sh: Permission denied
- 关于集合的有意义的代码 —— (一)
- 【京东2016研发工程师编程题】分苹果
- PAT--1069. The Black Hole of Numbers
- Eclipse启动时使用低版本JDK的问题
- 个人模拟面试之基础知识
- 将动画效果用于网页制作