-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagrams
More file actions
34 lines (28 loc) · 853 Bytes
/
Anagrams
File metadata and controls
34 lines (28 loc) · 853 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
import java.util.*;
import java.io.*;
import java.lang.*;
class Anagrams {
static boolean areAnagram(String s1, String s2)
{
if (s1.length() != s2.length())
return false;
char a1[]=s1.toCharArray();
Arrays.sort(a1);
s1=new String(a1);
char a2[]=s2.toCharArray();
Arrays.sort(a2);
s2=new String(a2);
return s1.equals(s2);
}
public static void main(String args[])
{
String str1 = "abaac";
String str2 = "aacba";
if (areAnagram(str1, str2))
System.out.println("The two strings are"
+ " anagram of each other");
else
System.out.println("The two strings are not"
+ " anagram of each other");
}
}