检测回文
程序员文章站
2022-04-14 19:04:16
package seday01; /** * char charAt(int index) 返回指定位置对应的字符 * @author xingsir */public class charAtDemo { public static void main(String[] args) { // 01 ......
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("是回文");
}
}