helping the code in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • capoeira26
    New Member
    • Sep 2009
    • 2

    helping the code in java

    Write a program that use a recursive method to check whether a string is a palindrome.this my code
    Code:
    public class Palindrome {
     
    void main(String[] args) {
            // TODO code application logic here
            char charArray[] = args[0].toCharArray();
        }
        
        public static Boolean testPalindrome(char[] text, int beg, int end) {
            //First case: the fragment in question is empty
            //This will be the case if beg is > end
            if(beg > end)
                return true;
            //Second case: the fragment contains just one character
            //This will be the case when beg == end.
            if(beg == end)
                return true;
            //Third case: is it of the form "x" + s + "x"
            
            if(testPalindrome(??, ?, ?))
            else
            return false;
        }           
    }
    Last edited by Frinavale; Sep 29 '09, 08:50 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Does it compile?Does it run?
    Give more details of where you are stuck.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Hehe :)
      I remember doing this for exam questions...mul tiple times. Seems to be one of those favorite questions asked.

      What seems to be the problem?
      Please don't just post code and expect us to try to figure out what you're doing, or what's wrong with what your doing. Please provide us with any error messages that you're getting and the specifics about what the problem might be.

      If I were you I'd write out the loop without using recursion first to get the logic right. Once I knew the logic I would convert the loop into a recursive loop.

      Comment

      Working...