Sunday, 7 June 2015

Program to check whether two strings are anagrams of each other

import java.io.*;
public class Anagrams
{
  public static void main(String args[]) throws Exception
  {
    Anagrams a = new Anagrams();
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    System.out.print("Enter first string: ");
    String str1 = br.readLine();
     
    System.out.print("Enter second string: ");
    String str2 = br.readLine();
    
    int flag = a.Anagram(str1, str2);

    if (flag==0)
    {
      System.out.print("\nResult: "+str1+" and "+str2+" are anagrams.");
    }
    else
    {
      System.out.print("\nResult: "+str1+" and "+str2+" are not anagrams.");
    }
    
    System.out.println();
  }


  public int Anagram(String str1,String str2)
  {
    if (str1.equals(str2))
    {
      return 0;
    }

    return 1;
  }
}
Output:
Enter first string: ana
Enter second string: ana

Result: ana and ana are anagrams.

Output2:
Enter first string: aana
Enter second string: ana

Result: aana and ana are not anagrams.

19 comments:

  1. Learning new technolgoy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.

    JAVA J2EE Training in Chennai | JAVA Training in Chennai | Hadoop training in chennai

    ReplyDelete
    Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

      Delete
  2. Thanks Mathew Stephen...n u said absolutely right that if we want to be in current position then we need to be updated...

    ReplyDelete
  3. Really cool post, highly informative and professionally written and I am glad to be a visitor of this perfect blog, thank you for this rare info! , Regards, servicenow training in hyderabad

    ReplyDelete
  4. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Web Designing Course in Chennai | web designing training in chennai

    ReplyDelete
  5. Thanks for sharing this unique and informative content which provided me the required information.
    Java Training in Chennai | JAVA Course in Chennai

    ReplyDelete
  6. Thanks for sharing the information about the java and keep updating us.
    JAVA Training in Chennai

    Best JAVA Training in Chennai

    ReplyDelete
  7. I agree with your thoughts!!! As the demand of java programming application keeps on increasing, there is massive demand for java professionals in software development industries. Thus, taking training will assist students to be skilled java developers in leading MNCs.Best Java Training in Chennai | Java Courses in Chennai|J2EE Training in Chennai

    ReplyDelete
  8. Thanks for sharing this useful and valuable information, keep updating your post.
    IT Job Training in Chennai

    ReplyDelete
  9. The expansion of internet and intelligence in business process lead the way to huge volume of data. It is important to maintain and process these data to be efficient in data handling. Hadoop Training in Chennai | Big Data Training in Chennai

    ReplyDelete
  10. I have read your blog its very Interesting. Thanks for sharing. Call for low cost ERP software. ERP in Chennai | ERP Software in Chennai

    ReplyDelete
  11. Thank you for this valuable information. I have got some important suggestions from it. I'm working in Brave Technologies Private Limited. We provides lowest price of ERP Software for our clients. Contact us on info@bravetechnologies.in. ERP Providers in Chennai

    ReplyDelete
  12. Nice post. Very interesting to read. Thank you for Sharing.
    erp software in chennai

    ReplyDelete
  13. Hi, like you post its more informative and thanks for sharing with us.
    Web D School

    ReplyDelete
  14. SV Soft Solutions is offering best Java online training with 100% job assistance and high quality training facilities and well expert faculty .
    to Register you free demo please visit Java Online Training Institute with Job Support

    ReplyDelete