From eadc6dc61314416f75ed76246192d773dbb3f4d7 Mon Sep 17 00:00:00 2001 From: Devansh Singh <95035769+Dev12820@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:40:00 +0530 Subject: [PATCH] Create Anagram.java --- algorithms/Java/arrays/Anagram.java | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 algorithms/Java/arrays/Anagram.java diff --git a/algorithms/Java/arrays/Anagram.java b/algorithms/Java/arrays/Anagram.java new file mode 100644 index 00000000..e16fbaab --- /dev/null +++ b/algorithms/Java/arrays/Anagram.java @@ -0,0 +1,34 @@ +import java.util.*; +public class Anagram { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + String s=sc.nextLine(); + String r=sc.nextLine(); + char ch[]=s.toCharArray(); + char dh[]=r.toCharArray(); + int d=ch.length; + int e=dh.length; + int c=0; + int dat[]=new int[26]; + for(int i=0;i0) + { + dat[ch[i]-97]++; + dat[dh[i]-97]--; + i++; + } + } + for(int j=0;j<26;j++) + if(dat[j]>0) + c++; + if(c==0) + System.out.println("Anagram"); + + } + }