//Anagram
import java.util.*;
class Anagram
{
String x;
int c=0;
Anagram(String n)
{
x=n;
}
public void print(String s1,String s2)
{
if(s2.length()<=1)
{
c++;
System.out.println(s1+s2);
}
else
{
for(int i=0;i<s2.length();i++)
{
String x=s2.substring(i,i+1);
String y=s2.substring(0,i);
String z=s2.substring(i+1);
print(s1+x,y+z);
}
}
}
}
public class Anagrammain
{
public static void main(String args[])
{
System.out.println("Enter the no.");
Scanner sc = new Scanner(System.in);
String x1=Integer.toString(sc.nextInt());
Anagram ob=new Anagram(x1);
ob.print("",x1);
System.out.println("Total no. of combinations is " + ob.c);
}
}
No comments:
Post a Comment
Convey your thoughts to authors.