charAt()检测回文
package seday01;
/**
* char charAt(int index) 返回指定位置对应的字符
* @author xingsir
*/
public class CharAtDemo {
public static void main(String[] args) {
// 0123456789012345(此为字符串下边位置)
String str = "thinking in java";
char c = str.charAt(2);
System.out.print(c);
/*
* 检测回文
*/
// 0123 5678 (此为字符串下边)
String line = "山东落花生花落东山";
for (int i = 0; i < line.length() / 2; i++) {
char c1 = line.charAt(i);
char c2 = line.charAt(line.length() - 1 - i);
if (c1 != c2) {
System.out.print("不");
break;
}
}
System.out.print("是回文");
}
}