-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCombination.java
More file actions
35 lines (32 loc) · 883 Bytes
/
Copy pathCombination.java
File metadata and controls
35 lines (32 loc) · 883 Bytes
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
public class Combination {
public static void combination(String str, char characters[], int bound, int depth, int next){
if (depth == bound){
for (int i = 0; i < bound; i++) {
System.out.print(characters[i]);
}
System.out.println();
return;
}
for (int i = next; i < str.length(); i++) {
characters[depth] = str.charAt(i);
combination(str, characters, bound, depth + 1, i + 1);
}
}
public static void main(String[] args) {
String str = "12345";
char characters[] = new char[str.length()];
int r = 3;
// prints:
// 123
// 124
// 125
// 134
// 135
// 145
// 234
// 235
// 245
// 345
combination(str, characters, r, 0, 0);
}
}