Sample Programming Assignment
Chapter 8
Permutations
- The Assignment:
-
You will implement and test a recursive method that prints
all permuations of a given string.
- Purposes:
- Ensure that you can write and test small recursive methods.
- Before Starting:
- Read all of Chapter 8, especially Sections 8.1 and 8.2.
- File that you must write:
-
-
Permuter.java:
This file should contain a class with at least two recursive methods
described below. Both of these methods are static.
You should also write a static main method that allows you
to test the other two methods.
- Independent Work:
- Keep in mind that you will not learn unless you do your own homework.
You may ask general questions of other students, and those
students may answer questions with pencil and paper. But do not
look at program files or other students' solutions to any
homework problem. Violating this requirement in any of your
classes will result in a failing grade for the entire semester.
1. Arrange
public static void arrange(String first, String second)
// Postcondition: All rearrangements of the letters in first, followed by
// second have been printed to System.out.
/* Example output:
arrange("CAT", "MAN") will print this:
CATMAN
CTAMAN
ACTMAN
ATCMAN
TACMAN
TCAMAN
*/
2. Permute
public static void permute(String s)
The method prints output consisting of all possible permutations of
the characters of s, with one permutation on each output line.
Michael Main
(main@colorado.edu)