EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

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”);

What is anagram in java language

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer