Menu

Hi, I need help with coding, can you help me turn this code in recursive function without using any loops:  This is a code for Palindrome: public class Palindrome { private boolean isPalindrome(Strin…

Question

Answered step-by-step

Hi, I need help with coding, can you help me turn this code in…

Hi, I need help with coding, can you help me turn this code in recursive function without using any loops: 

This is a code for Palindrome:

public class Palindrome {

private boolean isPalindrome(String word) {
 int i = 0, j = word.length() -1;
 while (i<j) {
   if (word.charAt (i) != word.charAt(j))
      return false;
   i++;
   j–; 
 }
 
 return true;
}
/*
 * Open up  the file.              
 * Break into words                                                   
 *  print out all Palindromes  
 */
private void findAllPalindromes(String fileName) {
}
public Palindrome() {
 //run some tests

 if (isPalindrome(“racecar”)) {
     System.out.print(“pass”);
 }
 else {
   System.out.print(“Fail”);
 }
 if (isPalindrome(“sister”)) {
    System.out.print(“pass”);
    }
 else {
   System.out.print(“Fail”);
 }
 if (isPalindrome(“noon”)) {
    System.out.print(“pass”);
    }
 else {
   System.out.print(“Fail”);
 }
   
  }

public static void main(String[] args) {
 new Palindrome();

}

}

Could you please help me turn into recursive function. 

OR

Leave a Reply

Your email address will not be published. Required fields are marked *