-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombination.java
More file actions
59 lines (43 loc) · 945 Bytes
/
Combination.java
File metadata and controls
59 lines (43 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Find Permutation of a number
import java.util.*;
public class Combination
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Eneter the String or Number U want to get Combination : \t");
String s=sc.nextLine();
System.out.println("");
System.out.println("My String Combination See Below!");
int n=s.length();
int l=n-1;
int f=0;
Combination permutation=new Combination();
permutation.permute(s,0,n-1);
}
private String Swap(String s1,int i,int j)
{
char temp;
char[] c=s1.toCharArray();
temp=c[i];
c[i]=c[j];
c[j]=temp;
return String.valueOf(c);
}
private void permute(String s,int f,int l)
{ int i;
if(f==l)
{
System.out.print(s+" ");
}
else{
for(i=f;i<=l;i++)
{
s=Swap(s,f,i);
permute(s,f+1,l);
s=Swap(s,f,i);
}
System.out.println();
}
}
}