判断回文串
代码如下:
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 + " 不是回文串");
}
}
}
只相信苦尽甘来