Java Reference
In-Depth Information
14. Write a recursive method called permut that accepts two integers n and r as parameters and returns the number of
unique permutations of r items from a group of n items. For given values of n and r , this value P(n, r) can be
computed as follows:
n !
P ( n , r )
=
( n
-
r )!
For example, permut(7, 4) should return 840 . It may be helpful to note that permut(6, 3) returns 120 , or 840 / 7.
15. The Sierpinski carpet is a fractal that is defined as follows: The construction of the Sierpinski carpet begins with a
square. The square is cut into nine congruent subsquares in a 3-by-3 grid, with the central subsquare removed. The
same process is then applied recursively to the eight other subsquares. Figure 12.7 shows the first few iterations of
the carpet.
Figure 12.7
Sierpinski carpet
Write a program to draw the carpet on a DrawingPanel recursively.
16. The Cantor set is a fractal that is defined by repeatedly removing the middle thirds of line segments as shown in
Figure 12.8.
Figure 12.8
Cantor set
Write a program to draw the Cantor set on a DrawingPanel recursively.
 
Search WWH ::




Custom Search