From 51e43257c3506908104f542958452e618eeb9d6d Mon Sep 17 00:00:00 2001 From: Sadman95 Date: Wed, 18 Oct 2023 12:06:33 +0600 Subject: [PATCH] added my solution for the Anagram problem under java directory --- JAVA/Anagram.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 JAVA/Anagram.java diff --git a/JAVA/Anagram.java b/JAVA/Anagram.java new file mode 100644 index 0000000..f62b43b --- /dev/null +++ b/JAVA/Anagram.java @@ -0,0 +1,27 @@ +import java.util.*; + +class Anagram { + public static void main(String[] args) { + + // Take an input scanner using Scanner instance + Scanner sc = new Scanner(System.in); + + // Take two strings as input + String a = sc.nextLine(); + String b = sc.nextLine(); + + // Covert two strings to array of characters + char[] arr1 = a.toCharArray(); + char[] arr2 = b.toCharArray(); + + // Sort those characters using sort method provided by the Arrays constructor + Arrays.sort(arr1); + Arrays.sort(arr2); + + // Conditionally print output checking those sorted strings are equal or not + if (Arrays.equals(arr1, arr2)) + System.out.print("YES"); + else + System.out.print("NO"); + } +} \ No newline at end of file