JavaNo Comments

default thumbnail

Two String is anagram which have same kind of characters but different order or way . Like Example : “Race”-“arce”,”Apple”-“pplae” . Here is how to check String is Anagram or not Anagram using java.

In Using Array Sort method :-Arraysort(character Array )

import java.util.*;
class gram
public static void main(String arg[])
Scanner sc=new Scanner(;
//word print..
System.out.println(” Enter First Word “);
//word stored in String.
String str=sc.nextLine();
//string change in chatacter Array..
char ch[]=str.toCharArray();
//sort the ch array
System.out.println(” Enter Second Word “);
String str1=sc.nextLine();
char ch1[]=str1.toCharArray();
for(int i=0;i<str.length();i++)
for(int j=0;j<str1.length();j++)
System.out.println(” This is Anagram ” );
System.out.println(” This is not Anagram “);


Be the first to post a comment.

Add a comment