-
Notifications
You must be signed in to change notification settings - Fork 5
/
Anagram Or Not
47 lines (38 loc) · 881 Bytes
/
Anagram Or Not
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
package practice;
import java.util.Arrays;
public class rough
{
static boolean status = true;
//keep and peek
static void Anagram(String s1,String s2)
{
String name1 = s1.replaceAll("\\s+", "");
String name2 = s2.replaceAll("\\s+", "");
if(name1.length() != name2.length())
{
status = false;
}
else
{
char array1[] = name1.toLowerCase().toCharArray();
char array2[] = name2.toLowerCase().toCharArray();
Arrays.sort(array1);
Arrays.sort(array2);
status = Arrays.equals(array1, array2);
}
}
static void display()
{
if(status == true)
System.out.println("Hence It Is An Anagram String");
else
System.out.println("Hence It Is Not An Anagram String");
}
public static void main(String args[])
{
Anagram("keep","peek");
display();//for display
Anagram("paras","bhatt");
display();//for display
}
}