Write a program to check if two given String is Anagram of each other.
/*
Write a program to check if two given String is Anagram of each other.
Your function should return true if two Strings are Anagram, false
otherwise. A string is said to be an anagram if it contains the same characters and same length, but in a
different order, e.g. army and Mary
are anagrams. You can ignore cases for this problem.
*/
import java.util.*;
class Twentytwo
{
public static void main(String arg[])
{
int a , b ;
Boolean f=true;
Scanner obj= new Scanner(System.in);
System.out.print("Enter 1st String : ");
String s1 = obj.nextLine();
System.out.print("Enter 2nd String : ");
String s2= obj.nextLine();
if( s1.length() == s2.length())
{
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<s1.length();j++)
{
if(s1.charAt(i)==s2.charAt(j))
{
f=true;
break;
}
else
{
f=false;
}
}
}
}
else
{
f=false;
}
if(f)
{
System.out.println(s1 + " & " + s2 + " Both String Are Anagrams");
}
else
{
System.out.println(s1 + " & " + s2 + " Both String Are Not Anagrams");
}
}
}
More Information on our channel Programmer Community
please like , share and subscribe to get notifications of new videos....
To understand this program video will coming soon on our you tube channel
Comments
Post a Comment