Page 418 - Computer science 868 Class 12
P. 418

29        }
                30        }while(!f);

                31        freq=0;
                32      }

                33        void print(String bs,String es)
                34        { if(es.length()<=1)  // base case

                35         { System.out.print(bs+es+" ");
                36          freq++;  // counting frequency

                37         }
                38         else

                39         { for(int i=0;i<es.length();i++)
                40          { String ns=es.substring(0,i)+es.substring(i+1);
                41           print(bs+es.charAt(i),ns); // recursive case

                42          }

                43        }
                44       }
                45       void call()

                46       { System.out.println("The anagrams are ");

                47        print("",str);  // calling recursive method
                48        System.out.println("Total number of anagrams = "+freq);
                49       }

                50       public static void main()
                51       { Anagram ob=new Anagram();  // object creation

                52        ob.accept();
                53        ob.call();

                54       }}
              The output of the preceding program is as follows:






















                416416  Touchpad Computer Science-XII
   413   414   415   416   417   418   419   420   421   422   423