package Others;
import java.util.Scanner;
public class ReturnSubsequence {
public static void main(String[] args) {
System.out.println("Enter String: ");
Scanner s = new Scanner(System.in);
String givenString = s.next();
String[] subsequence = returnSubsequence(givenString);
System.out.println("Subsequences : ");
for (int i = 0; i < subsequence.length; i++) {
System.out.println(subsequence[i]);
}
s.close();
}
private static String[] returnSubsequence(String givenString) {
if (givenString.length()
== 0)
{
String[] ans = new String[1];
ans[0] = "";
return ans;
}
String[] SmallAns =
returnSubsequence(
givenString.substring(
1));
String[] ans =
new String
[2 * SmallAns.length];
int i = 0;
for (; i < SmallAns.length; i++) {
ans[i] = SmallAns[i];
}
for (int k = 0; k < SmallAns.length; k++) {
ans[k + SmallAns.length] =
givenString.charAt(0)
+ SmallAns[
k];
}
return ans;
}
}