java - Permutations of a string -


public class permute {     public static void main(string[] args) throws ioexception {         system.out.println("enter string");         bufferedreader bufreader = new bufferedreader(new inputstreamreader(system.in));         string text = bufreader.readline();         shuffle("",text);     }     public static void shuffle(string dummy, string input){         if(input.length() <= 1)             system.out.println(dummy+input);         else{             for(int i=0; <input.length();i++){                 input = input.substring(i,1) + input.substring(0,i) + input.substring(i+1);                 shuffle(dummy+input.substring(0,1),input.substring(1));             }                    }     } } 

am trying print permutations of string entered. , cannot guess going wrong because on paper find executing. going wrong.

try change shuffle:

public static void shuffle(string dummy, string input){     if(input.length() <= 1)         system.out.println(dummy+input);     else{         for(int i=0; <input.length();i++){            shuffle(dummy+input.charat(i), input.substring(0, i) + input.substring(i+1, input.length()));         }                } } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -