Connecting Tech Pros Worldwide Forums | Help | Site Map

helping the code in java

Newbie
 
Join Date: Sep 2009
Location: Puerto Rico
Posts: 4
#1: Sep 26 '09
Write a program that use a recursive method to check whether a string is a palindrome.this my code
Expand|Select|Wrap|Line Numbers
  1. public class Palindrome {
  2.  
  3. void main(String[] args) {
  4.         // TODO code application logic here
  5.         char charArray[] = args[0].toCharArray();
  6.     }
  7.  
  8.     public static Boolean testPalindrome(char[] text, int beg, int end) {
  9.         //First case: the fragment in question is empty
  10.         //This will be the case if beg is > end
  11.         if(beg > end)
  12.             return true;
  13.         //Second case: the fragment contains just one character
  14.         //This will be the case when beg == end.
  15.         if(beg == end)
  16.             return true;
  17.         //Third case: is it of the form "x" + s + "x"
  18.  
  19.         if(testPalindrome(??, ?, ?))
  20.         else
  21.         return false;
  22.     }           
  23. }

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Sep 27 '09

re: helping the code in java


Does it compile?Does it run?
Give more details of where you are stuck.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,123
#3: Oct 2 '09

re: helping the code in java


Hehe :)
I remember doing this for exam questions...multiple 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.
Reply

Tags
java code