forked from codehouseindia/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutation.java
More file actions
22 lines (20 loc) · 595 Bytes
/
Permutation.java
File metadata and controls
22 lines (20 loc) · 595 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* This code will find all permutations of a given string
Recursion is used here*/
import java.util.ArrayList;
public class Permutation1 {
public static void main(String[] args) {
printPer("1234","");
}
//this method will find all permutations
public static void printPer(String ques,String ans){
if(ques.length()==0){
System.out.println(ans);
return;
}
for(int i=0;i<ques.length();i++){
char c=ques.charAt(i);
String ros=ques.substring(0,i)+ques.substring(i+1);
printPer(ros,ans+c);
}
}
}