Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions JAVA/Anagram.java
Original file line number Diff line number Diff line change
@@ -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");
}
}