Java Anagrams

  • + 1 comment

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=sc.next();
        boolean res=isAnagram(a,b);
        if(res){
            System.out.println("Anagrams");
        }
        else{
            System.out.println("Not Anagrams");
        }
     }
     static boolean isAnagram(String a,String b){
        a=a.toLowerCase();
        b=b.toLowerCase();
        if(a.length()!=b.length()){
            return false;
        }
        char ch1[]=a.toCharArray();
        char ch2[]=b.toCharArray();
        Arrays.sort(ch1);
        Arrays.sort(ch2);
        return Arrays.equals(ch1,ch2);
    

    } }