-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathStringCombinations.java
46 lines (32 loc) · 1004 Bytes
/
StringCombinations.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.demo.program.combination;
public class StringCombinations {
private StringBuilder output = new StringBuilder();
private final String inputstring;
private static int counter = 0;
public StringCombinations(final String str) {
inputstring = str;
System.out.println("The input string is : " + inputstring);
}
public static void main(String args[]) {
StringCombinations combobj = new StringCombinations("rahul");
System.out.println("");
System.out.println("All possible combinations are : ");
System.out.println("");
combobj.combine();
System.out.println("");
System.out.println("Total combinations :: " + counter);
}
public void combine() {
combine(0);
}
private void combine(int start) {
for (int i = start; i < inputstring.length(); ++i) {
output.append(inputstring.charAt(i));
System.out.println(output);
counter++;
if (i < inputstring.length())
combine(i + 1);
output.setLength(output.length() - 1);
}
}
}