判断是否是回文数或字符串
package com.baidu.zhidao;
import java.util.Scanner;
public class Palindrom {
public static void main(String[] args) {
while (true) {
try {
System.out.print("Waiting for type in:");
boolean flag = true;
Scanner s = new Scanner(System.in);
String str = s.next();
char[] ch = str.toCharArray();
for (int i = 0; i < ch.length / 2; i++) {
if (ch[i] != ch[ch.length - i - 1])
flag = false;
}
if (flag) {
System.out.println("This is a Palindrom:" + str);
}else{
System.out.println("This not is a Palindrom.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}