Java Reference
In-Depth Information
(a) Correct path
(b) Illegal path
F
IGURE
20.13
The program finds a path from the upper-left corner to the bottom-right corner.
**20.27
(
Koch snowflake fractal
) The text presented the Sierpinski triangle fractal. In
this exercise, you will write an applet to display another fractal, called the
Koch
snowflake
, named after a famous Swedish mathematician. A Koch snowflake is
created as follows:
1. Begin with an equilateral triangle, which is considered to be the Koch frac-
tal of order (or level)
0
, as shown in Figure 20.14a.
2. Divide each line in the shape into three equal line segments and draw an out-
ward equilateral triangle with the middle line segment as the base to create a
Koch fractal of order
1
, as shown in Figure 20.14b.
3. Repeat Step 2 to create a Koch fractal of order
2
,
3
, . . . , and so on, as shown
in Figure 20.14c-d.
(a)
(b)
(c)
(d)
F
IGURE
20.14
A Koch snowflake is a fractal starting with a triangle.
**20.28
(
Nonrecursive directory size
) Rewrite Listing 20.7, DirectorySize.java, without
using recursion.
*20.29
(
Number of files in a directory
) Write a program that prompts the user to enter
a directory and displays the number of the files in the directory.
**20.30
(
Find words
) Write a program that finds all occurrences of a word in all the files
under a directory, recursively. Pass the parameters from the command line as
follows:
VideoNote
Search a string in a directory
java Exercise20_30 dirName word
**20.31
(
Replace words
) Write a program that replaces all occurrences of a word with a
new word in all the files under a directory, recursively. Pass the parameters
from the command line as follows:
java Exercise20_31 dirName oldWord newWord