-
Notifications
You must be signed in to change notification settings - Fork 0
/
16- Java Anagrams.java
38 lines (28 loc) · 999 Bytes
/
16- Java Anagrams.java
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
/*
problem:
https://www.hackerrank.com/challenges/java-anagrams/problem
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
// get the inputs
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
String result;
// convert the strings into char arrays
a = a.toLowerCase();
b = b.toLowerCase();
char[] array1 = a.toCharArray();
char[] array2 = b.toCharArray();
// sort the two arrays, compare, and show the result
Arrays.sort(array1);
Arrays.sort(array2);
a = String.valueOf(array1);
b = String.valueOf(array2);
result = a.equals(b)? "Anagrams": "Not Anagrams";
System.out.println(result);
}
}