forked from ravitomar7/Lab_Test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagrans.java
More file actions
39 lines (34 loc) · 925 Bytes
/
Anagrans.java
File metadata and controls
39 lines (34 loc) · 925 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 Anagrans
{
public static void main(String args[])
{
String str1;
String str2;
Scanner s=new Scanner(System.in);
System.out.println("Enter String1:");
str1=s.nextLine();
System.out.println("Enter String2:");
str2=s.nextLine();
if (str1.length()==str2.length())
{
char[] arr1 = str1.toCharArray();
Arrays.sort(arr1);
char[] arr2 = str2.toCharArray();
Arrays.sort(arr2);
if(Arrays.equals(arr1, arr2))
{
System.out.println("Both Strings are anagrams");
}
else
{
System.out.println("Both Strings are not anagrams");
}
}
else
{
System.out.println("Strings are not anagram");
}
}
}