-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringpermutations.java
75 lines (60 loc) · 1.49 KB
/
Stringpermutations.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.Scanner;
import java.util.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Rosenkrantz
*/
public class Stringpermutations {
public static char[] arrange(char[] s)
{
for(int i=0;i<s.length;i++)
{
for(int j=1;j<s.length;j++)
{
if(Character.getNumericValue(s[j-1])>Character.getNumericValue(s[j]))
{
char t=s[j-1];
s[j-1]=s[j];
s[j]=t;
}
}
}
return s;
}
public static void main(String args[])
{ Scanner s=new Scanner(System.in);
System.out.println("Enter String 1");
String ss=s.next();
char[] bx=ss.toCharArray();
// System.out.println(Arrays.toString(bx));
System.out.println("Enter String 2");
String s1=s.next();
char[] bx1=s1.toCharArray();
bx=Stringpermutations.arrange(bx);
bx1=Stringpermutations.arrange(bx1);
System.out.println(Arrays.toString(bx));
System.out.println(Arrays.toString(bx1));
String fin1="";
String fin2="";
for(int i=0;i<bx.length;i++)
{
fin1+=bx[i];
}
for(int i=0;i<bx1.length;i++)
{
fin2+=bx1[i];
}
if(fin1.equals(fin2))
{ System.out.println("IS PERMUTATION");
}
else
{
System.out.println("IS NOT PERMUTATION");
}
//bx=Arrays.sort(bx);
}
}