-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString8.java
More file actions
33 lines (24 loc) · 835 Bytes
/
String8.java
File metadata and controls
33 lines (24 loc) · 835 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
import java.util.*;
public class String8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("Anagram Check:");
for (int i = 1; i <= n; i++) {
String str1 = sc.next();
String str2 = sc.next();
str1 = str1.toLowerCase();
str2 = str2.toLowerCase();
char[] a = str1.toCharArray();
char[] b = str2.toCharArray();
Arrays.sort(a);
Arrays.sort(b);
if (Arrays.equals(a, b)) {
System.out.println(i + ". " + str1 + " & " + str2 + " -> Anagram");
} else {
System.out.println(i + ". " + str1 + " & " + str2 + " -> Not Anagram");
}
}
sc.close();
}
}