Question

In: Computer Science

Write a recursive method to determine if a String is a palindrome. The program should contain...

Write a recursive method to determine if a String is a palindrome.

The program should contain a String array that you can load several test cases to test your palindrome testing method.

The program should load your String Array with the test data containing the possible palindromes from a text file.

The program should test you application with a text file contained in your project folder

After testing your program with your test cases in the text file, you program should allow the user to test your program independently and interactively using Command Line Interface (CLI).

*******The code must commented properly**********

**********  You must permit the user to enter their own palindrome after the test in run******************


JavaIntelliJ

Solutions

Expert Solution

Here i am providing the answer. Hope it helps. please give me a like. it helps me a lot. If any queries please do comment. i will be happy in clarifying.

Java code for above problem

import java.util.*;
import java.io.*;
class Main
{
   // tetsing main method
   public static void main(String args[]) throws IOException
   {
       // this following steps prints results of strings.txt file
       Scanner input=new Scanner(new File("strings.txt"));
       while(input.hasNext())
       {  
           String str=input.nextLine();
           System.out.println(isPalindrome(str));
       }
      
       // the following lines of codes takes input from user from command line and prints the result
       input=new Scanner(System.in);
       System.out.print("\nEnter a string: ");
       String str=input.nextLine();
       System.out.println(isPalindrome(str));
   }
  
   // method that returns the string saying the given string is palindrome or not
   public static String isPalindrome(String str)
   {
       if(isPalin(str,0,str.length()-1))
           return "\""+str+"\" is a palindrome";
       return "\""+str+"\" is not a palindrome";
   }
  
   // recursive method that says whether the given string is palindrome or not
   public static boolean isPalin(String str,int start,int end)
   {
       if(start>=end)
           return true;
       if(str.charAt(start)!=str.charAt(end))
           return false;
       return isPalin(str,start+1,end-1);
   }
}

Sample output

if "strings.txt" has following data

abcd
aaa
madam
string
radar
holidays
enjoy

then after running the above code, output looks as follows:

Thank you. please upvote.


Related Solutions

Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write a recursive method to determine if a String is a palindrome. Create a String array...
Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. In Java
Write a short recursive C++ function that determines if a string s is a palindrome, that...
Write a short recursive C++ function that determines if a string s is a palindrome, that is, it is equal to its reverse. For example,"racecar" and "gohangasalamiimalasagnahog" are palindromes. Please include the pseudo code so that I can understand better with simple English as much as possible.
c++ using recursive no loops (for ,while ..ect)not allowed Write a recursive function ‘bool palindrome(string s)’...
c++ using recursive no loops (for ,while ..ect)not allowed Write a recursive function ‘bool palindrome(string s)’ that returns true if s is a palindrome and false if not. #5: Write a recursive function 'void reverse(string &word)' that reverses the given input string. string name = "damian"; reverse(name); cout << name << endl; //should display "naimad". #7: Write a function 'int numTwos(int n)' which returns the number of 2's in the base-4 expansion of n. cout << numTwos(2170) << endl; //...
​Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.
Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.(JAVA Code)
Write a program that determines whether an input string is a palindrome; that is, whether it...
Write a program that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. In Pseudocode please
Write a RECURSIVE method that receives a string as a parameter. The method will return true...
Write a RECURSIVE method that receives a string as a parameter. The method will return true if the string received as a parameter is a palindrome and false if it is not. The method must not have any loops! In JAVA
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns an ArrayList in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the ArrayList and then reverse the...
java Write a recursive program to reverse a positive integer. . Your method should take a...
java Write a recursive program to reverse a positive integer. . Your method should take a non negative integer as a parameter and return the reverse of the number as an integer. e.g. if you pass 12345, your method should return 54321.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT