判断字符串是不是回文

来源:互联网 发布:漫画人物制作软件 编辑:程序博客网 时间:2024/04/30 00:35

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("该字符串不是回文字符串!");
           }
            
     }
}

http://hujinfan.javaeye.com/blog/761518