-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagram.java
More file actions
39 lines (35 loc) · 869 Bytes
/
Anagram.java
File metadata and controls
39 lines (35 loc) · 869 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
package java_Interview_Ques;
import java.util.Arrays;
public class Anagram {
public static void isAnagram(String str1,String str2)
{
String s1=str1.replaceAll("\\s", "");
String s2=str2.replaceAll("\\s", "");
boolean status=true;
if(s1.length()!=s2.length())
{
status=false;
}
else
{
char []Array1=s1.toLowerCase().toCharArray();
char []Array2=s2.toLowerCase().toCharArray();
Arrays.sort(Array1);
Arrays.sort(Array2);
status=Arrays.equals(Array1,Array2);
}
if(status)
{
System.out.println(s1+" and "+ s2 +" are Anagrams");
}
else
{
System.out.println(s1+ " and "+ s2 +" are Not Anagrams");
}
}
public static void main(String[] args)
{
isAnagram("keep","peek");
isAnagram("this is","is it");
}
}