Skip to content

Commit c9e6fbd

Browse files
author
Amar Kumar
authored
Anagram Checker
In this program user enter two string then it check it's anagram or not.
1 parent 7f1df0c commit c9e6fbd

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Check this string is anagram or not

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.Arrays;
2+
3+
class Main {
4+
public static void main(String[] args) {
5+
String str1 = "java";
6+
String str2 = "vaaj";
7+
8+
9+
if(str1.length() == str2.length()) {
10+
11+
12+
char[] charArray1 = str1.toCharArray();
13+
char[] charArray2 = str2.toCharArray();
14+
15+
16+
Arrays.sort(charArray1);
17+
Arrays.sort(charArray2);
18+
19+
20+
boolean result = Arrays.equals(charArray1, charArray2);
21+
22+
if(result) {
23+
System.out.println(str1 + " and " + str2 + " are anagram.");
24+
}
25+
else {
26+
System.out.println(str1 + " and " + str2 + " are not anagram.");
27+
}
28+
}
29+
else {
30+
System.out.println(str1 + " and " + str2 + " are not anagram.");
31+
}
32+
}
33+
}
34+
35+

0 commit comments

Comments
 (0)