Answers for "anagram program"

1

anagram java program

import java.util.Arrays;
public class StringAnagramProgram
{
   public static void main(String[] args)
   {
      String strOne = "Silent";
      String strTwo = "Listen";
      strOne = strOne.toLowerCase();
      strTwo = strTwo.toLowerCase();
      // checking if two strings length are same
      if(strOne.length() == strTwo.length())
      {
         // converting strings to char array
         char[] charOne = strOne.toCharArray();
         char[] charTwo = strTwo.toCharArray();
         // sorting character array
         Arrays.sort(charOne);
         Arrays.sort(charTwo);
         // if sorted character arrays are same then the string is anagram
         boolean output = Arrays.equals(charOne, charTwo);
         if(output)
         {
            System.out.println(strOne + " and " + strTwo + " are anagram.");
         }
         else
         {
            System.out.println(strOne + " and " + strTwo + " are not anagram.");
         }
      }
      else
      {
         System.out.println(strOne + " and " + strTwo + " are not anagram.");
      }
   }
}
Posted by: Guest on November-22-2021
3

python anagrams

# function to check if two strings are 
# anagram or not  
def check(s1, s2): 
      
    # the sorted strings are checked  
    if(sorted(s1)== sorted(s2)): 
        print("The strings are anagrams.")  
    else: 
        print("The strings aren't anagrams.")          
          
# driver code   
s1 ="listen"
s2 ="silent" 
check(s1, s2)
Posted by: Guest on May-13-2020
9

anagram python

def isAnagram(A,B):
  if sorted(A) == sorted(B):
    print("Yes")
  else:
    print("No")
isAnagram("earth","heart") #Output: Yes

#Hope this helps:)
Posted by: Guest on February-21-2021
1

anagram

#take user input
String1 = input('Enter the 1st string :')
String2 = input('Enter the 2nd string :')
#check if length matches
if len(String1) != len(String2):
    #if False
    print('Strings are not anagram')
else:
    #sorted function sort string by characters
    String1 = sorted(String1)
    String2 = sorted(String2)
    #check if now strings matches
    if String1 == String2:
        #if True
        print('Strings are anagram')
    else:
         print('Strings are not anagram')
Posted by: Guest on May-19-2021
0

Anagram

const anagram = (str1, str2) => {
    return str1.toLowerCase().split('').sort().join('') === str2.toLowerCase().split('').sort().join('');
};

let test = anagram('Regallager', 'Lagerregal');
console.log(test);
Posted by: Guest on July-21-2021

Python Answers by Framework

Browse Popular Code Answers by Language