-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagramPrgm.java
More file actions
39 lines (28 loc) · 839 Bytes
/
AnagramPrgm.java
File metadata and controls
39 lines (28 loc) · 839 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
38
39
package core;
import java.io.*;
import java.util.Arrays;
public class AnagramPrgm {
public static void main(String[] args) throws IOException {
boolean status=true;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter First String");
String name1 = br.readLine();
System.out.println("Enter Second String");
String name2 = br.readLine();
if(name1.length()!=name2.length())
{
status=false;
}else {
char[] arr1=name1.toLowerCase().toCharArray();
char[] arr2=name2.toLowerCase().toCharArray();
Arrays.sort(arr1);
Arrays.sort(arr2);
status=Arrays.equals(arr1, arr2);
}
if(status) {
System.out.println("String is an anagram");
}else {
System.out.println("Not an anagram");
}
}
}