Advertisement
eldieck

Untitled

Feb 24th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. public class MainClass {
  2.   public static void main(String args[]) {
  3.     permuteString("", "String");
  4.   }
  5.  
  6.   public static void permuteString(String beginningString, String endingString) {
  7.     if (endingString.length() <= 1)
  8.       System.out.println(beginningString + endingString);
  9.     else
  10.       for (int i = 0; i < endingString.length(); i++) {
  11.         try {
  12.           String newString = endingString.substring(0, i) + endingString.substring(i + 1);
  13.  
  14.           permuteString(beginningString + endingString.charAt(i), newString);
  15.         } catch (StringIndexOutOfBoundsException exception) {
  16.           exception.printStackTrace();
  17.         }
  18.       }
  19.   }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement