File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #https ://www.facebook.com/permalink.php?story_fbid=2038372642966043&id=100003799820060
2+ #Subscribed by Kattebaaz
3+ import java .util .Arrays ;
4+
5+ public class AnagramString {
6+ static void isAnagram (String str1 , String str2 ) {
7+ String s1 = str1 .replaceAll ("\\ s" , "" );
8+ String s2 = str2 .replaceAll ("\\ s" , "" );
9+ boolean status = true ;
10+ if (s1 .length () != s2 .length ()) {
11+ status = false ;
12+ } else {
13+ char [] ArrayS1 = s1 .toLowerCase ().toCharArray ();
14+ char [] ArrayS2 = s2 .toLowerCase ().toCharArray ();
15+ Arrays .sort (ArrayS1 );
16+ Arrays .sort (ArrayS2 );
17+ status = Arrays .equals (ArrayS1 , ArrayS2 );
18+ }
19+ if (status ) {
20+ System .out .println (s1 + " and " + s2 + " are anagrams" );
21+ } else {
22+ System .out .println (s1 + " and " + s2 + " are not anagrams" );
23+ }
24+ }
25+
26+ public static void main (String [] args ) {
27+ isAnagram ("Keep" , "Peek" );
28+ isAnagram ("Mother In Law" , "Hitler Woman" );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments