import java.util.Scanner;
public class Anagram {
public static void main(String[] args) {

Scanner input = new Scanner(;
System.out.println("Enter your first string: ");
String string1 = input.nextLine();
System.out.println("Enter your second string: ");
String string2 = input.nextLine();


if (isAnagram(sort(string1), sort(string2)) == true){

System.out.println("not Anagrams");

/// sort string- by converting String->char->string

public static String sort(String s){
char[] s1 = new char[s.length()];
s1 = s.toCharArray();

s = new String(s1);
return s;

public static boolean isAnagram(String s1, String s2){
return s1.equals(s2);




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: