└── README.md /README.md: -------------------------------------------------------------------------------- 1 | / Java program to print all the permutations 2 | // of the given string 3 | 4 | public class GFG { 5 | 6 | 7 | // Function to print all the permutations of str 8 | 9 | static void printPermutn(String str, String ans) 10 | 11 | { 12 | 13 | 14 | // If string is empty 15 | 16 | if (str.length() == 0) { 17 | 18 | System.out.print(ans + " "); 19 | 20 | return; 21 | 22 | } 23 | 24 | 25 | for (int i = 0; i < str.length(); i++) { 26 | 27 | 28 | // ith character of str 29 | 30 | char ch = str.charAt(i); 31 | 32 | 33 | // Rest of the string after excluding 34 | 35 | // the ith character 36 | 37 | String ros = str.substring(0, i) + 38 | 39 | str.substring(i + 1); 40 | 41 | 42 | // Recursive call 43 | 44 | printPermutn(ros, ans + ch); 45 | 46 | } 47 | 48 | } 49 | 50 | 51 | // Driver code 52 | 53 | public static void main(String[] args) 54 | 55 | { 56 | 57 | String s = "abb"; 58 | 59 | printPermutn(s, ""); 60 | 61 | } 62 | } 63 | --------------------------------------------------------------------------------