-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagramCheck.java
More file actions
37 lines (33 loc) · 1001 Bytes
/
Copy pathAnagramCheck.java
File metadata and controls
37 lines (33 loc) · 1001 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
package testString;
import java.util.Arrays;
import java.util.Scanner;
public class AnagramCheck {
static boolean b = true;
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter 1st String ");
String str1 = s.nextLine();
System.out.println("Enter 2nd String ");
String str2 = s.nextLine();
str1.trim();
str2.trim();
str1.toLowerCase();
str2.toLowerCase();
if(str1.length() == str2.length()) {
char[] ch1 = str1.toCharArray();
char[] ch2 = str2.toCharArray();
Arrays.sort(ch1);
Arrays.sort(ch2);
if(Arrays.equals(ch1, ch2) == true) {
System.out.println("Both the strings are anagram");
}
else {
System.out.println("Both the strings are not anagram");
}
}
else {
System.out.println("Both the strings are not anagram");
}
s.close();
}
}