File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ /* Generate subtes of a given string
2
+ */
3
+ import java .util .Scanner ;
4
+ public class StringSubset {
5
+ static void SubSets (String str , String current , int index ){
6
+ if (index ==str .length ()) {
7
+ System .out .println (current + " " );
8
+ return ;
9
+ }
10
+ /* Two cases for every character
11
+ (i) We consider the character as part of current subset
12
+ (ii) We do not consider current character as part of current subset */
13
+ SubSets (str ,current +str .charAt (index ), index +1 );
14
+ SubSets (str ,current , index +1 );
15
+
16
+ }
17
+ //Driver code
18
+ public static void main (String [] args ) {
19
+ Scanner scan = new Scanner (System .in );
20
+ System .out .println ("Enter the string you want to generate substrings of" );
21
+ String str = scan .nextLine ();
22
+ int index =0 ;
23
+ String current = "" ;
24
+ SubSets (str ,current ,index );
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments