-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanagram.java
47 lines (35 loc) · 999 Bytes
/
anagram.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
39
40
41
42
43
44
45
46
47
import java.util.Arrays;
import java.util.Scanner;
class anagram
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
String str1,str2;
char[] charArray1;
char[] charArray2;
System.out.print("Enter first String: ");
str1 = sc.nextLine();
System.out.print("Enter second String: ");
str2 = sc.nextLine();
if(str1.length() == str2.length()) {
charArray1 = str1.toCharArray();
charArray2 = str2.toCharArray();
Arrays.sort(charArray1);
Arrays.sort(charArray2);
boolean result = Arrays.equals(charArray1, charArray2);
if(result)
{
System.out.println(str1 + " and " + str2 + " are anagram.");
}
else
{
System.out.println(str1 + " and " + str2 + " are not anagram.");
}
}
else
{
System.out.println(str1 + " and " + str2 + " are not anagram.");
}
}
}