-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathAditi.java
More file actions
70 lines (69 loc) · 1.55 KB
/
Aditi.java
File metadata and controls
70 lines (69 loc) · 1.55 KB
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
import java.util.*;
class q2
{
boolean checkAnagram(String s1,String s2)
{
int f=0;
String a= s1;
String b= s2;
String n1= a;
String n2= b;
if(a.length()==b.length())
{
int l= a.length();
char x[]= new char[l];
char y[]= new char[l];
for(int i= 0; i<a.length(); i++)
{
x[i]= a.charAt(i);
y[i]= b.charAt(i);
}
for(int i=0; i<n1.length(); i++)
{
for(int j=0; j<n2.length(); j++)
{
char k= n1.charAt(i);
char r= n2.charAt(j);
if(k==r)
{
n2= n2.substring(0,j)+n2.substring(j+1);
f++;
break;
}
}
}
if(f==l)
{
return (true);
}
else
{
return (false);
}
}
else
{
return (false);
}
}
public static void main(String args[])
{
Scanner in= new Scanner (System.in);
String s1, s2;
System.out.println("Enter first word");
s1= in.nextLine();
s1= s1.toLowerCase();
System.out.println("Enter second word");
s2= in.nextLine();
s2= s2.toLowerCase();
q2 obj= new q2();
if (obj.checkAnagram(s1,s2)== true)
{
System.out.println("Both the strings are anagram of each other");
}
else
{
System.out.println("Both the strings are not anagram of each other");
}
}
}