- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaAnagrams.java
More file actions
Latest commit
35 lines (27 loc) · 846 Bytes
/
Copy pathJavaAnagrams.java
File metadata and controls
35 lines (27 loc) · 846 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
packageStrings;
importjava.util.Scanner;
publicclassJavaAnagrams {
staticbooleanisAnagram(Stringa, Stringb) {
char[] cha = a.toLowerCase().toCharArray(),
chb = b.toLowerCase().toCharArray();
if (cha.length != chb.length) {
returnfalse;
}
java.util.Arrays.sort(cha);
java.util.Arrays.sort(chb);
for (intx = 0, l = cha.length; x < l; x++) {
if (cha[x] != chb[x]) {
returnfalse;
}
}
returntrue;
}
publicstaticvoidmain(String[] args) {
Scannerscan = newScanner(System.in);
Stringa = scan.next();
Stringb = scan.next();
scan.close();
booleanret = isAnagram(a, b);
System.out.println( (ret) ? "Anagrams" : "Not Anagrams" );
}
}