判断字符串是否为回文字符串(Java版)

迭代不就是循环么...来个for循环就O了吧,试试这个...
public class Palindrome{
public boolean isPalindrome(String[] str) {
int len = str.length;
boolean b = false;

for(int i = 0; i <= len/2; i++ ) {
if(str[i] != str[len-i-1]) {
break;
} else {
b = true;
}

}

return b;
}

public static void main(String[] args) {
String[] str = {"L","V","E","V","L"};

if(new Palindrome().isPalindrome(str) ) {
System.out.println("该字符串是回文字符串!");
} else {
System.out.println("该字符串不是回文字符串!");
}

}
}

你可能感兴趣的:(判断字符串是否为回文字符串(Java版))