Guest User

Untitled

a guest
Oct 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. package edu.msud.cs.cs1;
  2.  
  3. import edu.princeton.cs.introcs.StdArrayIO;
  4.  
  5. import java.util.Arrays;
  6.  
  7. public class Permutation {
  8.  
  9.  
  10. void printPermutations (String head, String tail)
  11. {
  12. if(tail.length() == 0) System.out.println(head);
  13. else {
  14. for (int i = 0; i < tail.length()-1; i++) {
  15. StringBuffer newTail = new StringBuffer(tail);
  16. newTail.deleteCharAt(i);
  17. printPermutations(head + tail.charAt(i), newTail.toString());
  18.  
  19. }
  20. }
  21.  
  22. }
  23.  
  24. public static void main(String[] args) {
  25. char[] az = {'a', 'b', 'c', 'd', 'e', 'f',
  26. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  27. 'p', 'q', 'r', 's', 't', 'u', 'v',
  28. 'w', 'x', 'y', 'z'};
  29.  
  30. String str = new String();
  31. for(int i = 0; i < Integer.parseInt(args[0]); i++)
  32. {
  33. str += az[i];
  34. }
  35. Permutation permutation = new Permutation();
  36. permutation.printPermutations("",str);
  37.  
  38.  
  39.  
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment