Question: JAVA 6. Write a recursive method with this prototype: void permute(String first, String second) // Postcondition: The output consists of lines of Strings. Each String

JAVA

6. Write a recursive method with this prototype: void permute(String first, String second) // Postcondition: The output consists of lines of Strings. Each String // is made by writing some rearrangement of first followed by all // of second. // For example, if first is "CAT" and second is "MAN", then there will // be six lines of output: // CATMAN // ACTMAN // TCAMAN // CTAMAN // ATCMAN // TACMAN

Hints: The stopping case occurs when the length of first is zero (in which case the method prints second). Some String methods that will help you for a String s: o s.length( ) is the length of s. o s.charAt(s.length( ) - 1) is a copy of the last character of s. o System.out.println(s) will print s. o s = (String.valueOf(c) + s) will insert the character c at the front of s. o s = (s + String.valueOf(c)); will insert the character c at the end of s. o s = s.substring(1) will remove one character from the front of s. o s = s.substring(0, s.length( )-1) will remove the last character from s.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!