Skip to content

Commit 9379b5a

Browse files
authored
Merge pull request #76 from anjupriya-v/main
Anagram
2 parents 0ce32fd + fe2f9ad commit 9379b5a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Anagram.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
import java.util.*;
3+
class Anagram{
4+
public static void main(String args[]){
5+
String str1,str2;
6+
Scanner sc=new Scanner(System.in);
7+
System.out.println("Enter the String 1");
8+
str1=sc.nextLine();
9+
System.out.println("Enter the String 2");
10+
str2=sc.nextLine();
11+
if(str1.length()!=str2.length()){
12+
System.out.println("The Strings "+str1+" and"+str2+" is not a Anagram");
13+
}
14+
else{
15+
str1=str1.toLowerCase();
16+
str2=str2.toLowerCase();
17+
char[]arr1=str1.toCharArray();
18+
char []arr2=str2.toCharArray();
19+
Arrays.sort(arr1);
20+
Arrays.sort(arr2);
21+
if(Arrays.equals(arr1,arr2)==true){
22+
System.out.println("The Strings "+str1+" and"+str2+" is a Anagram");
23+
}
24+
else{
25+
System.out.println("The Strings "+str1+" and"+sātr2+" is not a Anagram");
26+
}
27+
}
28+
}
29+
}
30+
31+
32+

0 commit comments

Comments
 (0)