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 743ea99 commit a24d15cCopy full SHA for a24d15c
CodingBlocks Training/Day11/StringPermutations.java
@@ -0,0 +1,29 @@
1
+package Lecture11;
2
+
3
+public class StringPermutations {
4
5
+ public static void main(String[] args) {
6
7
+ String str = "abc";
8
+ String result = "";
9
10
+ printPermutation(str, result);
11
+ }
12
13
+ public static void printPermutation(String str, String result) {
14
15
+ if (str.length() == 0) {
16
+ System.out.println(result);
17
+ return;
18
19
20
+ for (int i = 0; i < str.length(); i++) {
21
+ char current = str.charAt(i);
22
+ String before = str.substring(0, i);
23
+ String after = str.substring(i + 1);
24
+ String rest = before + after;
25
26
+ printPermutation(rest, result + current);
27
28
29
+}
0 commit comments