finding if two words are anagrams of each other

后端 未结 22 1295
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 14:51

I am looking for a method to find if two strings are anagrams of one another.

Ex: string1 - abcde
string2 - abced
Ans = true
Ex: string1 - abcde
string2 - ab         


        
22条回答
  •  悲&欢浪女
    2020-11-27 15:31

    in java we can also do it like this and its very simple logic

    import java.util.*;
    
    class Anagram
    {
     public static void main(String args[]) throws Exception
     {
      Boolean FLAG=true;
    
      Scanner sc= new Scanner(System.in);
    
      System.out.println("Enter 1st string");
    
      String s1=sc.nextLine();
    
      System.out.println("Enter 2nd string");
    
      String s2=sc.nextLine();
    
      int i,j;
      i=s1.length();
      j=s2.length();
    
      if(i==j)
      {
       for(int k=0;k

提交回复
热议问题