Skip to content

Commit

Permalink
Added Anagram oftwo strings (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivaraj2003 authored Oct 7, 2024
1 parent 2e6ac11 commit ccc580e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode/
.vscode/
*.class
56 changes: 56 additions & 0 deletions Java/Anagram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// # Anagram

// ## Problem Statement

// Write a program that takes two strings as input and determines if they are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another.

// Your program should print "Anagram" if the two input strings are anagrams and "Not Anagram" if they are not.

// ## Input

// - Two strings, `str1` and `str2`, consisting of lowercase or uppercase letters and spaces.

// ## Output

// - "Anagram" if the two input strings are anagrams.
// - "Not Anagram" if the two input strings are not anagrams.

// ## Example

// #### Input
// str1 = "listen"
// str2 = "silent"

// #### Output
// Anagram




import java.util.*;

public class Anagram{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String s1,s2;
System.out.println("Enter string 1");
s1=sc.next();
System.out.println("Enter string 2");
s2=sc.next();

char arr1[] = s1.toCharArray();
char arr2[] = s2.toCharArray();

Arrays.sort(arr1);
Arrays.sort(arr2);

boolean res = Arrays.equals(arr1,arr2);

if(res==true)
System.out.println("Anagram");
else
System.out.println("Not Anagram");

}
}

0 comments on commit ccc580e

Please sign in to comment.