-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathprogram.java
More file actions
44 lines (33 loc) · 983 Bytes
/
program.java
File metadata and controls
44 lines (33 loc) · 983 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
40
41
42
43
44
import java.util.*;
public class Prg{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Taking two string as a input
String first = sc.next();
String second = sc.next();
int a[] = new int[26];
int b[] = new int[26];
// Storing thier ascii index value in array
for(int i =0; i<first.length(); i++){
int index = (int) first.charAt(i);
a[index-97]++;
}
for (int i =0; i<second.length(); i++){
int index = (int) second.charAt(i);
b[index-97]++;
}
// for checking their index for frequency of aplhabet
boolean is = true;
for(int i =0; i<26; i++){
if(a[i] != b[i]){
is = false;
break;
}
}
if(is == true){
System.out.println("strings are Anagram..");
}else{
System.out.println("Strings sre not Anagram..");
}
}
}