We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e6cf6d2 commit 41f4818Copy full SHA for 41f4818
CodingBlocks Training/Day11/printStringSubsequences.java
@@ -0,0 +1,40 @@
1
+package Lecture11;
2
+
3
+public class printStringSubsequences {
4
5
+ public static void main(String[] args) {
6
7
+ String str = "abc";
8
+ String result = "";
9
10
+ printSubsequences(str, result);
11
+ }
12
13
+ public static void printSubsequences(String str, String result) {
14
15
+ if (str.length() == 0) {
16
+ System.out.println(result);
17
+ return;
18
19
20
+ char first = str.charAt(0);
21
+ String restStr = str.substring(1);
22
23
+ printSubsequences(restStr, result);
24
25
+ printSubsequences(restStr, result + first);
26
27
+}
28
29
+/*
30
+output:
31
32
+c
33
+b
34
+bc
35
+a
36
+ac
37
+ab
38
+abc
39
+*/
40
+// note first line of output here is blank space which is also the part of subsequence
0 commit comments