-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagram.java
More file actions
36 lines (27 loc) · 837 Bytes
/
Anagram.java
File metadata and controls
36 lines (27 loc) · 837 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
import java.util.Arrays;
import java.util.Scanner;
public class Anagram {
public static boolean Anagaramm(String s1, String s2){
if(s1.length() != s2.length()){
return false;
}
char[] ch = s1.toCharArray();
char[] ch2 = s2.toCharArray();
Arrays.sort(ch);
Arrays.sort(ch2);
return Arrays.equals(ch, ch2);
}
public static void main(String[] args) {
try(Scanner sc = new Scanner(System.in);){
System.out.println("Enter the First string ");
String s1 = sc.nextLine();
System.out.println("Enter the second string ");
String s2 = sc.nextLine();
if(Anagaramm(s1, s2)){
System.out.println("String are Anagram");
}else{
System.out.println("String are not Anagram");
}
}
}
}