-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAnagrams.java
More file actions
39 lines (30 loc) · 764 Bytes
/
Anagrams.java
File metadata and controls
39 lines (30 loc) · 764 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.Arrays;
import java.util.Scanner;
public class JavaAnagrams {
static boolean IsAnagram ( String a , String b) {
int al = a.length();
int bl = b.length();
boolean result = true;
if(al!=bl) {
result = false;
}
else
{
char aArray [] = a.toLowerCase().toCharArray();
char bArray [] = b.toLowerCase().toCharArray();
Arrays.sort(aArray);
Arrays.sort(bArray);
result = Arrays.equals(aArray , bArray);
System.out.println(result);
}
return result;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String a = s.next();
String b = s.next();
boolean result = IsAnagram(a,b);
System.out.println((result)? "Anagrams": "Not Anagrams");
s.close();
}
}