Question: In Java Write a program LongestPalindromicSubsequence that takes a string as a command line argument and determines the longest subsequence of the string that is
In Java
Write a program LongestPalindromicSubsequence that takes a string as a command line argument and determines the longest subsequence of the string that is a palindrome ( the same when read forward and backward). Hint: Compute the longest common subsequence of the string and its reverse.

Here is what I have so far help me finish the TODO.
1 package edu.msud.cs.csl; 3 public class LargestPalindrome t 4. private String str, palindrome; public LargestPalindrome (String input) str Input ; palindrome = 9 longest PalisuD(str, str.length()); 10 12 private boolean isPalindrome (String s) // use to test the substrings 13 return s.equals((new StringBuffer (s)).reverse().toString)) 15 16 17 private String longestPalisub(String s, int length) I/ this is the recursive function /I TODO I Hint: Use ArrayList to collect the substrings of a particular 1ength I Hint: You terminate the recursion when you find a palindrome or length1 I Hint: Up to you whether to consider a single character a palindrome /I Note: There might be more than one palindrome of the same length (e.g. mama) 20 21 23 return""; 25 26 27 28 29 30 31 32 public String get) return palindrome; public static void main(String[] args) System.out.println((new LargestPalindrome("alcohol")).get)) // should print "oho" System.out.println((new LargestPalindrome("alhambra")).get()) // should print nothing System.out.println((new LargestPalindrome ("tattarrattat")).get())// should print "tattarrattat" 34 35
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
