-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprg1.java
More file actions
59 lines (51 loc) · 1.19 KB
/
prg1.java
File metadata and controls
59 lines (51 loc) · 1.19 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
import java.util.*;
class prg1
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
String Str1 = in.nextLine();
String Str2 = in.nextLine();
int[] a = new int[30];
int[] b = new int[30];
int flag = 0;
for(int i=0;i<30;i++)
{
a[i] = 0;
b[i] = 0;
}
if(Str1.length() == Str2.length())
{
Str1.toLowerCase();
Str2.toLowerCase();
for( int i =0 ; i < Str1.length() ; i++)
{
char c1 = Str1.charAt(i);
char c2 = Str2.charAt(i);
a[c1 - 97]++;
b[c2 - 97]++;
}
flag = 1;
for(int i =0; i < 30 ; i++)
{
if(a[i]!=b[i])
{
flag = 0;
break;
}
}
}
else
{
flag = 0;
}
if(flag == 1)
{
System.out.println("are anagrams");
}
else
{
System.out.println("not anagrams");
}
}
}