Question: import java.io . * ; import java.util. * ; / * * * LongestCommonSubsequence is a program that will determine the longest string that is
import java.io;
import java.util.;
LongestCommonSubsequence is a program that will determine the longest string that is
a subsequence of two input strings. This program applies a brute force solution technique.
@author Charles Hoot
@version
public class LongestCommonSubsequence
public static void mainString args
BagInterface toCheckContainer null;
Scanner input;
input new ScannerSystemin;
System.out.printlnThis program determines the longest string that is a subsequence of two input string.";
System.out.printlnPlease enter the first string:";
String first input.next;
System.out.printlnPlease enter the second string:";
String second input.next;
ADD CODE HERE TO CREATE THE BAG WITH THE INITIAL STRING
vvvvvvvvv ADDED CODE vvvvvvvvvvvvvvvvvvvvvvvv
toCheckContainer new ArrayBag;
toCheckContainer.addfirst;
toCheckContainer.addsecond;
System.out.printlnThe strings to check are: toCheckContainer;
String bestSubsequence new String;
ADD CODE HERE TO CHECK THE STRINGS IN THE BAG
whiletoCheckContainer.isEmpty
String current toCheckContainer.remove;
ifisSubsequencecurrent second && current.length bestSubsequence.length
bestSubsequence current;
System.out.printlnFound bestSubsequence for the longest common subsequence";
Determine if one string is a subsequence of the other.
@param check See if this is a subsequence of the other argument.
@param against The string to check against.
@return A boolean if check is a subsequence of other.
public static boolean isSubsequenceString check, String against
boolean result false;
ADD CODE HERE TO CHECK IF WE HAVE A SUBSEQUENCE
ifchecklength against.length return false;
int index ;
forint i; i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
