In: Computer Science
Write a RECURSIVE method that receives 2 strings as parameters. The method will return true if the 2nd string is a subsequence of the 1st string. If not, the method will return false.
An empty string is a subsequence of every string. This is because all zero characters of the empty string will appear in the same relative order in any string
This method must not contain any loops.
In java
import java.io.*;
class SubSequence
{
static boolean isSubSequence(String str1, String str2,
int m, int n)
{
if (m == 0)
return
true;
if (n == 0)
return
false;
if (str1.charAt(m-1) ==
str2.charAt(n-1))
return
isSubSequence(str1, str2, m-1, n-1);
return isSubSequence(str1, str2, m,
n-1);
}
public static void main (String[] args)
{
String str1 = " "; //ENTER YOUR
STRINGS BETWEEN THE DOUBLE INVERTED COMMA
String str2 = " ";
int m = str1.length();
int n = str2.length();
boolean res = isSubSequence(str1,
str2, m, n);
if(res)
System.out.println("TRUE");
else
System.out.println("FALSE");
}
}