-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanagram.java
31 lines (27 loc) · 864 Bytes
/
anagram.java
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
import java.util.Arrays;
import java.util.Scanner;
public class anagram {
public static boolean Anagram(String str1,String str2){
if(str1.length() != str2.length()){
return false;
}
char charArr1[] = str1.toCharArray();
char charArr2[] = str2.toCharArray();
Arrays.sort(charArr1);
Arrays.sort(charArr2);
return Arrays.equals(charArr1,charArr2);
}
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.print("enter the string 1 : ");
String str1 = input.nextLine();
System.out.print("enter the string 2 : ");
String str2 = input.nextLine();
if(Anagram(str1,str2)){
System.out.print("it is a anagram.");
}
else{
System.out.print("it is not");
}
}
}