Write in java to input a word and print its anagrams. NOTE- Anagrams are words made up of all characters present in the original word by rearranging the characters

Write in java to input a word and print its anagrams.

NOTE- Anagrams are words made up of all characters present in the original word by rearranging the characters
Example:
Input : pot
Output : top, otp, tpo, top, pot,opt.

Answer:

import java.util.*;

public class string   

  {

  public static void main(String args[] )

   {

    String str;

    int i,j,k,p;

    Scanner in=new Scanner (System.in);

    System.out.println("Enter a three letter word");

    str=in.next();

    p=str.length();

    System.out.println("The required combination of the word :");

    for(i=0;i<p;i++)

    {

     for(j=0;j<p;j++)

     {

      for(k=0;k<p;k++)

      {

       if(i!=j&&j!=k&&k!=1)

       System.out.print(str.charAt(i)+""+str.charAt(j)+""+str.charAt(k));

      }

      System.out.println();

             }  

        } 

   }                    

Output:



Post a Comment

0 Comments