判断是否定是回文字
2019-02-28 本文已影响30人
一条IT
public static boolean IsHuiwen(String word) {
StringBuilder sb = new StringBuilder(word);
String wordReverse = sb.reverse().toString();
return wordReverse.equals(word);
}
//不需要任何方法判断是否是回文
public static boolean IsHuiwen2(String word) {
boolean isHuiwen = true;
int len = word.length();
//levvel
for(int i = 0; i < len / 2; i++)
{
if(word.charAt(i) != word.charAt(len - 1 - i))
{
isHuiwen = false;
break;
}
}
return isHuiwen;
}
public static void main(String[] args) {
// System.out.println("level".charAt(0));
System.out.println(IsHuiwen2("levveel"));
}