-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathAnagram.java
More file actions
32 lines (29 loc) · 833 Bytes
/
Anagram.java
File metadata and controls
32 lines (29 loc) · 833 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
import java.io.*;
import java.util.*;
class Anagram{
public static void main(String args[]){
String str1,str2;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String 1");
str1=sc.nextLine();
System.out.println("Enter the String 2");
str2=sc.nextLine();
if(str1.length()!=str2.length()){
System.out.println("The Strings "+str1+" and"+str2+" is not a Anagram");
}
else{
str1=str1.toLowerCase();
str2=str2.toLowerCase();
char[]arr1=str1.toCharArray();
char []arr2=str2.toCharArray();
Arrays.sort(arr1);
Arrays.sort(arr2);
if(Arrays.equals(arr1,arr2)==true){
System.out.println("The Strings "+str1+" and"+str2+" is a Anagram");
}
else{
System.out.println("The Strings "+str1+" and"+sātr2+" is not a Anagram");
}
}
}
}