-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaAnagrams.java
More file actions
37 lines (27 loc) · 879 Bytes
/
JavaAnagrams.java
File metadata and controls
37 lines (27 loc) · 879 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
import java.util.Scanner;
public class Solution {
static boolean isAnagram(String a, String b) {
int[] counterA= new int[256];
int[] counterB= new int[256];
a=a.toUpperCase();
b=b.toUpperCase();
for(int i=0; i<a.length();i++){
counterA[(int)a.charAt(i)]++;
}
for(int i=0; i<b.length();i++){
counterB[(int)b.charAt(i)]++;
}
for(int i=0; i<256;i++)
if(counterA[i]!=counterB[i])
return false;
return true;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String a = scan.next();
String b = scan.next();
scan.close();
boolean ret = isAnagram(a, b);
System.out.println( (ret) ? "Anagrams" : "Not Anagrams" );
}
}