What is an Anagram?
An anagram is a word or phrase formed by rearranging the letters of another word or phrase, using all the original letters exactly once.
✅ Example of Anagrams:
“listen” → “silent”
“race” → “care”
“evil” → “vile”
“a gentleman” → “elegant man” (ignoring spaces and case)
✅ Rules for Anagram:
Both words/phrases must have the same length.
They must have identical letters with the same frequency.
Case is usually ignored, and spaces/punctuation are ignored when comparing phrases.
Check whether both the strings are Anagram or not
x= silent
y= listen
x=abcd
y=dbac
String x,y;
Scanner s=new Scanner(System.in);
System.out.println(“enter string1 and string2:”);
x=s.nextLine();//silent
y=s.nextLine();//LisTen
x=x.toLowerCase();//silent
y=y.toLowerCase();//listen
char a[]=x.toCharArray(); s i l e n t
char b[]=y.toCharArray(); l i s t e n
Arrays.sort(a);
Arrays.sort(b);
boolean result=Arrays.equals(a,b);
if(result==true)
System.out.println(“Anagram”);
else
System.out.println(“not anagaram”);