判断回文串

代码如下:

package ClassDemo;
import java.util.Scanner;
public class CheckPalindrome {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a string: ");
String s = input.nextLine();
int low = 0;
int high = s.length()-1;
boolean flag = true;
while (low < high) {
if(s.charAt(low) != s.charAt(high)) {
flag = false;
break;
}
low++;
high--;
}
if (flag) {
System.out.println(s + " 是回文串");
} else {
System.out.println(s + " 不是回文串");
}
}
}

posted @ 2017-06-20 16:36  辰峰  阅读(134)  评论(0编辑  收藏  举报