word display wordfirst letter remaining letters action cat yes at rotate at cta yes ta rotate ta cat no at rotate cat atc yes tc rotate tc act yes ct rotate ct atc no tc rotate atc tca yes ca rotate ca tac yes ac rotate ac tca no ca rotate tca cat no at done notice that we must rotate back to the starting point with two letters before performing -letter rotation this leads to sequences like catctacat the redundant combinations aren' displayed how do we anagram the rightmost - lettersby calling ourselves the recursive doanagram(method takes the size of the word to be anagrammed as its only parameter this word is understood to be the rightmost letters of the complete word each time doanagram(calls itselfit does so with word one letter smaller than beforeas shown in figure the base case occurs when the size of the word to be anagrammed is only one letter there' no way to rearrange one letterso the method returns immediately otherwiseit anagrams all but the first letter of the word it was given and then rotates the entire word these two actions are performed timeswhere is the size of the word here' the recursive routine doanagram()public static void doanagram(int newsizeif(newsize = /if too smallreturn/go no further for(int = <newsizej++/for each positiondoanagram(newsize- )/anagram remaining