For example given string is "ABC" then possible combinations are "ABC","ACB","BAC","BCA","CAB" and "CBA". Here is the example.
public class permutation { public static void main(String[] args) { perM("","ABC"); } private static void perM(String bigin,String end) { if(end.length()<=1){ System.out.println(bigin+end); }else{ for(int i=0;i<end.length();i++){ String str=end.substring(0,i)+end.substring(i+1); perM(bigin+end.charAt(i),str); } } } }
No comments:
Post a Comment