-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagramProblem.java
More file actions
34 lines (32 loc) · 1.04 KB
/
AnagramProblem.java
File metadata and controls
34 lines (32 loc) · 1.04 KB
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
package corejava;
import java.util.Arrays;
import java.util.Scanner;
public class AnagramProblem {
/*
* An Anagram is a word or phrase that made by transposing the letter of two words or phrase
* like "Parliament" is anagram of "partial men" and also "software" is a anagram of "Swear oft"
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the frst string : ");
String s1 = sc.nextLine();
System.out.print("Enter the second string :");
String s2 = sc.nextLine();
if(s1.length()== s2.length()) {
char[] arr1 = s1.toCharArray();
char[] arr2 = s2.toCharArray();
Arrays.sort(arr1);
Arrays.sort(arr2);
boolean Result = Arrays.equals(arr1, arr2);
if(Result) {
System.out.println("The two String "+ s1 + " and " + s2 + " are anagrams");
}
else {
System.out.println("The two String "+ s1 + " and " + s2 + " are not anagrams");
}
}
else {
System.out.println("The two String "+ s1 + " and " + s2 + " are not anagrams");
}
}
}