-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnagramTester.java
More file actions
39 lines (39 loc) · 996 Bytes
/
AnagramTester.java
File metadata and controls
39 lines (39 loc) · 996 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
import java.util.Scanner;
class AnagramTester
{
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("enter two String");
String first = sc.nextLine();
String second=sc.nextLine();
Anagram a = new Anagram();
//Step 1-removing spaces
first= a.removeSpc(first);
second=a.removeSpc(second);
//step-2 cheaking length
if(first.length()!=second.length())
{
System.out.println("These two String are not anagram");
return;
}
//Step-3 Converting lower case.
first= a.toLowerCase(first);
second=a.toLowerCase(second);
//step-4 Shorting character of String
first = a.sort(first);
second=a.sort(second);
//Step-5 Comparing character one by one.
char c1[]=first.toCharArray();
char c2[]=second.toCharArray();
for(int i =0;i<c1.length;i++)
{
if(c1[i]!=c2[i])
{
System.out.println("These two string are not anagram.");
return;
}
}
System.out.println("yes both are anagram finally...");
}
}