Using Java programming String Permutation Write a recursive

Using Java programming (String Permutation) Write a recursive method to print all the permutations of a string. For example, for string abc, the permutation is abc acb bac bca cab cab

Solution

   public static void getPerm(String str) {

   getPerm(\"\", str);

   }

   private static void getPerm(String pfix, String s) {

   int hat = s.length();

   if (hat == 0) System.out.println(pfix);

   else {

   for (int i = 0; i < hat; i++)

   getPerm(pfix + s.charAt(i), s.substring(0, i) + s.substring(i+1, hat));

   }

   }

Using Java programming (String Permutation) Write a recursive method to print all the permutations of a string. For example, for string abc, the permutation is

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site