package demo;
import java.util.Scanner;
public class HuiWenShu {
static String string;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s;
System.out.println("请输入要检验的串:");
string = scanner.next();
if (huiWenChuan(string)) {
s = "此字符串是回文串!";
}else {
s = "此字符串不是回文串!";
}
System.out.println(s);
}
private static boolean huiWenChuan(String string) {
// TODO Auto-generated method stub
int low = 0;
int heigh = string.length()-1;
while (low<heigh) {
if (string.charAt(low)!=string.charAt(heigh)){ //检查对称位置是否一致
return false;
}
low++;
heigh--;
}
return true;
}
}
java实现检查输入字符串是不是回文串
最新推荐文章于 2024-07-19 08:16:25 发布